in reply to Re^2: Data managing problem
in thread Data managing problem
Sure
First the switches: perl -anle"..."
This has the effect of placing the -e"..." within a while loop very similar to this:
while( <> ) { ... # the -e snippet here }
Now the -e snippet code in three parts:
This builds %h with the second field of each input line as the key; and the whole line ($_) prefixed with the line number ($.) as the value.
Later lines with matching second fields will overwrite earlier ones.
This has the effect of converting the while loop shown above into:
while( <> ) { ... # the part of the -e snippet before the }{ here; runs for ever +y line in the file. }{ # closes the while loop body and puts a bare block after it ... # The part of the -e snippet after the }{ goes here and is only + executed after the input is exhausted. }
It a little like adding an END{} block containing the second half of the -e snippet.
One we've read all the input, only the last line with each second field value will remain in the hash, prefixed with the line number it came from.
So sort the values from %h to get them into line number order and then print them out having removed the line numbers.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Data managing problem
by tmharish (Friar) on Feb 22, 2013 at 13:52 UTC | |
by BrowserUk (Patriarch) on Feb 22, 2013 at 14:10 UTC | |
by tmharish (Friar) on Feb 22, 2013 at 14:17 UTC |