I have read the relevant passages in perl cookbook and learning perl, but I am unsure how to deal with the anonymous fileglob produced from an indirect filehandle. How do I close the file?
The code is unfinished, but you can see where I am unsure at the end of it:
cleaned up the syntax errors, but now problem is error:"can't open -100 No file or directory ..."# split-unix.pl -- do split in perl # # usage:split [-num] file [outname] my $outfile = "x"; #default my $limit = 1000; my $readfile; my $s1= "a"; if (scalar(@ARGV) > 3){ usage; } if($ARGV[0] =~/^[0-9]+/){ $limit = -$ARGV[0]; shift @ARGV; } $readfile = $ARGV[0]; shift @ARGV; if (defined $ARGV[0]){ $outfile = $ARG[0]; } $outfile.=$s1; open ($write, ">", $outfile) or die "$0: can't open $outfile $!"; open ($fh, "<", $readfile) or die "$0: can't open $readfile $!"; while(<>){ if ($. < $limit){ print; } else{ $outfile++; $write=""; # I think this answers my question open ($write, ">", $outfile) or die "$0: can't open $outfile $!"; } }
In reply to dynamic filenames, indirect filehandles by jjohhn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |