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

zodell:

If you just want to unconditionally remove everything before the first comma, I'd suggest using split, like this:

while (my $line = ..datasource..) { my ($first, $rest) = split /,/, $line, 2; print $OFH $rest; }

Update: Removed erroneous comma after $OFH, thanks to Tux.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

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

Replies are listed 'Best First'.
Re^2: Removing everything before the first comma separator on each line of a text file
by Tux (Canon) on Sep 16, 2014 at 06:21 UTC

    That will remove all the comma's from the rest of the line.

    It will also break if one of the fields is quoted and contains a newline.

    Bad advice

    update: The comma after $OFH will also cause havoc :P


    Enjoy, Have FUN! H.Merijn

      nope, split leaves the delimiters in after the LIMIT (just tested with perl 5.14.2).

      Admittedly, the documentation says "substrings (called "fields") that do not include the separator", so one could expect an implementation of split which filters out the delimiters from the "rest field", but I have heard the "P" in "Perl" stands for "practical" :-)

      your update about the comma after print$OFH is correct, of course...