CIS 33A Perl handout week 11 part 2
Preliminary material should be here.
Sample programs from Clare Nguyen (edited by Ira Oldham)
############## shell I/O ############
Lecture week 11 hour 2 Example shell I/O
#########################
### system system "date"; system "who | head"; $var = "infile"; system "grep 34 $var"; ### use ` ` print `pwd`; foreach $person (`who`) { $count++; } print $count,"\n"; $user = `who | head`; print "as a string: $user\n"; @user = `who | head`; print "as a list: @user\n"; ### use open open(WHO, "who |") or warn "can't open who: $!\n"; while (<WHO>) { $count ++ } close WHO; print "$count\n"; open (LIST, "ls |") or warn "can't open ls: $!\n"; @dir_listing = <LIST>; close LIST; print "@dir_listing[0..4]\n"; #open (LPR, "| lpr") or warn "can't open lpr: $!\n"; #print LPR @dir_listing; #close LPR;