in reply to Re: Stripping a seemingly complicated comma-delimited file
in thread Stripping a seemingly complicated comma-delimited file

#!/usr/local/bin/perl -w open(HIPORT,"eq010125.txt"); $file = <HIPORT>; $i = 0; while ($file =~ /\n$/) { chop $file; ($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10,$var11,$ +var12,$var13,$var14) = split(/[,]|[,]|\n$/,$file); print "$i : $var1 $var2 $var3 $var4 $var5 $var6 $var7 $var8 $var9 +$var10 $var11 $var12 $var13 $var14 \n"; $i++; }

Replies are listed 'Best First'.
Re: Re: Re: Stripping a seemingly complicated comma-delimited file
by virtualsue (Vicar) on Jun 11, 2001 at 18:21 UTC
    #!/usr/local/bin/perl -w # GOOD! open(HIPORT,"eq010125.txt");
    Please check the error from your file open. What if it fails? open(HIPORT,"eq010125.txt") or die "Couldn't open file, $!"; However, your main problem is that you are assigning the contents of your file to a scalar - $file.
    $file = <HIPORT>; You definitely don't want to do that. @file = <HIPORT>; will suck the contents of the file into an array for you. I strongly suggest that you start off with code that reads your file line by line. You are trying to do far too much work. Use the program I have posted or any one of the similar programs that others have put up. :)
Re: Re: Re: Stripping a seemingly complicated comma-delimited file
by the_slycer (Chaplain) on Jun 11, 2001 at 18:22 UTC
    The problem that you are running into here is with this line
    $file = <HIPORT>;
    What you have done there is not what you think. When you assing $file to the <> operator it grabs one line - not every line. Either assign it to an array (@file) which will put each line as an array entry, or even better loop through the file with
    while my $file(<HIPORT>){ #do stuff }