1 / 9

파일 및 디렉토리(1)

파일 및 디렉토리(1). 여러 함수들 chdir(“category”) || die “cannot cd to temp”; chdir(“..”); unlink(“file_temp”); rename($file, “new_dir/large$file”); mkdir(“new_dir”, 0777); # 0666(R/W), 0444 (R) rmdir(“old_dir); chmod(0666, $file);. 파일 및 디렉토리(2). Globbing : 파일/디렉토리 리스트

merton
Télécharger la présentation

파일 및 디렉토리(1)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 파일 및 디렉토리(1) • 여러 함수들 • chdir(“category”) || die “cannot cd to temp”; • chdir(“..”); • unlink(“file_temp”); • rename($file, “new_dir/large$file”); • mkdir(“new_dir”, 0777); # 0666(R/W), 0444 (R) • rmdir(“old_dir); • chmod(0666, $file);

  2. 파일 및 디렉토리(2) • Globbing : 파일/디렉토리 리스트 • Command shell은 *.bak을 매칭되는 화일 리스트로 변환한다 • @a = <*.bak>; • @a = glob(“[1-9]*”); foreach $file ( <*.bak>) { # step through a list of .bak files unlink($file) || warn “having trouble deleting $file: $!”; }

  3. 파일 및 디렉토리(3) • 디렉토리 핸들러 (파일 핸들러와 비슷) • opendir(NT, “c:/winnt”); • readdir(NT); # returns next file name or name list • closedir(NT); while ( $name = readdir(NT) ) { print “$name\n”; } closedir(NT);

  4. 파일 및 디렉토리(4) • 파일/디렉토리 리스트 성질 테스트 • -r : 파일이나 디렉토리를 읽을 수 있는가? • -w: 쓸수 있나? –e : 존재하나? • -x : 수행할 수 있나? • -z, -s, -f, -d, -T, -B, 등등…. print “which file ? “; $filename = <STDIN>; chomp $filename; # newline 특수문자 제거 if ( -r $filename && -w $filename) { # file exits, and can be read and wrote ….}

  5. 파일 및 디렉토리(예) #!/usr/local/bin/perl mkdir ("category", 0777); @files = glob("[1-6]*"); foreach $file ( @files ) { rename( $file, "category/s$file"); }

  6. 프로세스 관리 • system(), fork(), wait() 등의 함수 • system() 함수 • system(“nmake fred bedrock > output”); • fork()함수 • 지금 수행되는 프로세스의 복사판을 만든다 • Parent process는 >0 값을 갖고 • Child Process는 0의 값을 갖는다 • wait()함수 • Child process가 끝날 때까지 기다린다

  7. 프로세스 관리(예) #!/usr/local/bin/perl $start = $ARGV[0]; $file = $ARGV[1]; if ( $pid = fork() ) { sleep 120; $ppid = getppid; kill 9, $ppid; exit -1;} elsif ( defined $pid ) { print "Handling ISBN $start \n"; system "java GetKISBN $start >> $file "; exit 0; }

  8. Win32 Perl과 Apache(1) • www.activestate.com • Win32용 Binary가 제공됨 • www.apache.org • Win 32용 Apache 서버가 제공됨 • www.php.net • Win 32용 Binary가 제공됨 • Guestbook이나 ASP예제를 손 쉽게 이식할 수 있음

  9. Win32 Perl과 Apache(2) #!D:\Perl\bin\perl.exe use OLE; # use Win32::OLE if using the Std Distribution $Conn = CreateObject OLE "ADODB.Connection"; $Conn->Open("DSN=Sample;UID=;PWD="); print "Content-type: text/html\n\n"; print '<HTML>'; print '<HEAD>'; $RS = $Conn->Execute("SELECT * FROM tblSample"); if(!$RS) { $Errors = $Conn->Errors(); print "Errors:\n"; foreach $error (keys %$Errors) { print $error->{Description}, "\n"; } die; } while ( !$RS->EOF ) { my($Last, $First, $City) = ( $RS->Fields('LastName')->value, $RS->Fields('FirstName')->value, $RS->Fields('City')->value ); print $Last, " : ", $First, " : ", $City, "<p>\n"; $RS->MoveNext; } $RS->Close; $Conn->Close; print '</BODY>'; print '</HTML>';

More Related