jjohhn has asked for the wisdom of the Perl Monks concerning the following question:
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 $!"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: dynamic filenames, indirect filehandles
by rupesh (Hermit) on May 19, 2005 at 04:07 UTC | |
by jjohhn (Scribe) on May 19, 2005 at 04:19 UTC | |
by TheStudent (Scribe) on May 19, 2005 at 04:33 UTC | |
Re: dynamic filenames, indirect filehandles
by jdporter (Paladin) on May 19, 2005 at 04:14 UTC | |
by jjohhn (Scribe) on May 19, 2005 at 04:24 UTC | |
by jjohhn (Scribe) on May 19, 2005 at 12:02 UTC |