in reply to Re: Removing everything before the first comma separator on each line of a text file
in thread Removing everything before the first comma separator on each line of a text file

I would also have to write a whole new script or section to be able to parse through the input file and have code that would insert the regex statement to each line, and also would not serve the purpose that I am trying to accomplish.

  • Comment on Re^2: Removing everything before the first comma separator on each line of a text file

Replies are listed 'Best First'.
Re^3: Removing everything before the first comma separator on each line of a text file
by Laurent_R (Canon) on Sep 16, 2014 at 17:40 UTC
    This part of your code:
    my @file = <INFILE>; my $reg = s/[^,]*\.(\S*)//; while (my $line = <INFILE>){ chomp $line; my $wholefile = $line.$_ foreach(@file); print OUTFILE $wholefile; }
    is most probably wrong anyway, so you might as well rewrite it completely. Either slurp the file into an array and then process the array elements, or read the file line by line and process each line in turn, but don't try to do both. Here, you read the whole file into the @file array and then try to read from that file again line by line, this is not going to work. In addition, in the while loop that is supposed to read the file, you loop on the array again, which is a faulty logic. You are "saved" from that silly process only because the while loop will in fact not loop on the file handler, because the file handler is exhausted at this point.