I'm also very new to Perl and wrote a long and newbyish script
does exactly what the Unix command "sort FILENAME | uniq"
does just to
see how it can be done.
How long? Because you can do that on one line in perl. :-)does just to
see how it can be done.
I've just come back to your post above (30/05/05) and I've tried to
get the internal workings of the code to agree with my brain. Please
help!
perl -e'print sort grep !$seen{$_}++, <>' FILENAME
Initially I thought you were creating a hashref(?) key with every lineof input, if unique. But I cannot access the keys using the hashref
(below) so there is something else at work here.
for $key_v (keys %{$seen}) {
print "$key_v\n";
}
This returns nothing when used with the above code in a script (code
posted at request). Sorry in advance if I've made newbie mistake but
please explain how !$seen{$_}++ knows what was used before.
PS Will the Perl Cookbook have examples to common tools such as this?
What does everyone think of the book - very helpful?
TIA
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This e-mail and its contents are subject to the Telkom SA Limited
e-mail legal notice available at
http://www.telkom.co.za/TelkomEMailLegalNotice.PDF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~