9
파파 파 파파파파 (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);

파일 및 디렉토리(1)

  • Upload
    merton

  • View
    35

  • Download
    0

Embed Size (px)

DESCRIPTION

파일 및 디렉토리(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 : 파일/디렉토리 리스트 - PowerPoint PPT Presentation

Citation preview

Page 1: 파일 및 디렉토리(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);

Page 2: 파일 및 디렉토리(1)

파일 및 디렉토리 (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: $!”;

}

Page 3: 파일 및 디렉토리(1)

파일 및 디렉토리 (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);

Page 4: 파일 및 디렉토리(1)

파일 및 디렉토리 (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

….}

Page 5: 파일 및 디렉토리(1)

파일 및 디렉토리 ( 예 )

#!/usr/local/bin/perl

mkdir ("category", 0777);

@files = glob("[1-6]*");

foreach $file ( @files ) {

rename( $file, "category/s$file");

}

Page 6: 파일 및 디렉토리(1)

프로세스 관리

• system(), fork(), wait() 등의 함수– system() 함수

• system(“nmake fred bedrock > output”);

– fork() 함수 • 지금 수행되는 프로세스의 복사판을 만든다• Parent process 는 >0 값을 갖고• Child Process 는 0 의 값을 갖는다

– wait() 함수• Child process 가 끝날 때까지 기다린다

Page 7: 파일 및 디렉토리(1)

프로세스 관리 ( 예 )#!/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;

}

Page 8: 파일 및 디렉토리(1)

Win32 Perl 과 Apache(1)

• www.activestate.com– Win32 용 Binary 가 제공됨

• www.apache.org– Win 32 용 Apache 서버가 제공됨

• www.php.net– Win 32 용 Binary 가 제공됨

• Guestbook 이나 ASP 예제를 손 쉽게 이식할 수 있음

Page 9: 파일 및 디렉토리(1)

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>';