in reply to Stripping a seemingly complicated comma-delimited file

You need to post the code to show us how you are storing the data before you split it. If you are reading each line from a file and splitting it straight away the while loop will be something like
while (<FILE_HANDLE>){ @items = split /,/; # do something with @items }

Or if you have the lines in an array use a foreach loop:

foreach ( @lines ){ # split in here }

The while statement you have shown stays true for as long as there is a new line, it does not move through the data.

-- iakobski

Replies are listed 'Best First'.
Re: Re: Stripping a seemingly complicated comma-delimited file
by jamesSA (Initiate) on Jun 11, 2001 at 18:03 UTC
    #!/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++; }
      #!/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. :)
      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 }