#file: fileio.pl #desc: test file i/o $filename = ""; for ($i=0; $i<= $#ARGV; $i++) { print "argument no " . ($i+1) . " is $ARGV[$i]\n"; if ($ARGV[$i] eq "-s") { if ($i+1 <= $#ARGV) { $filename = $ARGV[$i+1]; } else { print "cheater! -s was the last argument!\n"; } } } print "filename is *$filename*\n"; ### test if file exists if (-e $filename) { print "file $filename exists\n"; print "OPENING FILE...\n"; open (FILE, "$filename") or die("could not open file $filename"); print "FILE OPENED OK\n"; close(FILE); print "FILE CLOSED\n"; } else { print "file $filename DOES NOT EXIST!\n"; }