in reply to how to substitute next line with nothing

You can use split to accomplish this

split
  • Comment on Re: how to substitute next line with nothing

Replies are listed 'Best First'.
Re^2: how to substitute next line with nothing
by CountZero (Bishop) on Feb 23, 2009 at 06:59 UTC
    split is indeed the basis of getting the fields from each record, but generally it is a poor choice to use this for CSV-files. Text::CSV takes care of all the edge cases and will save you a lot of trouble in the long run.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^2: how to substitute next line with nothing
by rovf (Priest) on Feb 23, 2009 at 11:44 UTC

    I think the question was not how to extract the fields, but how to exclude duplicate records.

    I think in this case it's easiest to just use a hash to record the names, for example:

    my %seen=(); ... while(<INPUT_FILE>) { my @fields=split /=/; $fields[1]=/^(\d+)/; my $id=$1; $fields[2]=/^(\w*)/; my $name=$1; $seen{$name}=[$id,$fields[5]]; }
    If a name occurs several times, the last occurence is recorded and the other ones discarded.

    -- 
    Ronald Fischer <ynnor@mm.st>