in reply to Re: dynamic filenames, indirect filehandles
in thread dynamic filenames, indirect filehandles

I tried that; my program print the error:
C:\scripts>perl split-unix.pl -100 tinysat tmp Can't open -100: No such file or directory at split-unix.pl line 27.
<-- contents of the file-->
Can't open tmp: No such file or directory at split-unix.pl line 28, <> line 16.
It also writes an empty file "tmpa".
  • Comment on Re^2: dynamic filenames, indirect filehandles

Replies are listed 'Best First'.
Re^3: dynamic filenames, indirect filehandles
by jjohhn (Scribe) on May 19, 2005 at 12:02 UTC
    The problem is solved; thanks for your patience with my ill-formed question that turned out not to be the problem at all.
    # split-unix.pl -- do split in perl # # usage:split [-num] file [outname] use strict; my $outfile = "x"; #default my $limit = 1000; my $readfile; my $s1= "a"; if($ARGV[0] =~/^-?[0-9]+/){ $limit = 0- $ARGV[0]; shift @ARGV; } $readfile = $ARGV[0]; shift @ARGV; if (defined $ARGV[0]){ $outfile = $ARGV[0]; } $outfile.=$s1; open (OUT, ">", $outfile) or die "$0: can't open $outfile $!"; open (IN, "<", $readfile) or die "$0: can't open $readfile $!"; print OUT $limit; #=pod while(<IN>){ if ($. > $limit ){ close OUT; $outfile++; open(OUT, ">", $outfile) or die "$0: can't open $outfile $!"; } print OUT "$_"; } #=cut close OUT;