On 3/1/07, oryann9 <[EMAIL PROTECTED]> wrote:
snip
> perl -ne 'print unless $h{(split/:/)[0]}++'
This is creating a anonymous hash, correct?
snip
No, the hash is named %h. The proper way to read $h{(split/:/)[0]}++
is "Increment the value whose key in %h is the first element of $_
when split on ':'." The following code does the same thing, but
requires a lot more typing:
#!/usr/bin/perl
use strict;
use warnings;
my %seen;
while (<>) {
my $key = (split /:/)[0];
if (exists $seen{$key}) {
$seen{$key}++;
} else {
$seen{$key} = 1;
print;
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/