in reply to Re^5: Checking LInes in Text File
in thread Checking LInes in Text File

Grandfather,

Thank you very much!!! I really appreciate you solving that problem for me. I'm very new to PERL and have to admit that your code took a while to make sense to me. I didn't realize that you could access an array by the data value, I thought you had to access it by location (0,1,2,3... etc). Thanks again for your help!

Replies are listed 'Best First'.
Re^7: Checking LInes in Text File
by GrandFather (Saint) on Jun 02, 2006 at 23:38 UTC

    Just in case there is some confusion or misunderstanding of some of the Perl tricks used I better go through some of that code and elaborate on what's happening. Note that I've taken interesting lines in processing order rather that the order they are coded.

    $firstLines{$data} = @lines;

    this is a little tricksy. It creates a new entry in %firstLines that contains the index to the new line as the value and is keyed by the unique part of the line contents. @lines in scalar context returns the number of elements in the array.

    if (exists $firstLines{$data})

    checks to see if we've already seen a specific line.

    $lines[$firstLines{$data}] .= ", $type";

    builds the multiple entries for duplicated lines. Note that $firstLines{$data} returns the index number that was stored earlier.


    DWIM is Perl's answer to Gödel
      Thanks much for the added commentary! Now I think I actually understand what you did.