Charles K. Clarkson wrote:
Ing. Branislav Gerzo <[EMAIL PROTECTED]> wrote:
: Charles K. Clarkson [CKC], on Monday, November 15, 2004 at
: 09:20 (-0600) typed: : : : : $seen{$item} ? $seen{$item}++ : $seen{$item} = 1; }
: : $seen{$item} = $seen{$item} ? ++$seen{$item} : 1;
: : ok I understand, but I don't know why my line doesn't work. I
: thought (exp) ? (true) : (false) is the same as if (exp) { }
: else { }
Try this:
perl -e 'my %seen = (foo => 0,bar =>1); for(keys %seen) { $seen{$_} += $seen{$_} ? 0 : 1;print "$_ : $seen{$_}\n"; }'
instead of this:
perl -e 'my %seen = (foo => 0,bar =>1); for(keys %seen) { $seen{$_} ? $seen{$_}++ : $seen{$_} = 1;print "$_ : $seen{$_}\n"; }'
Or to simplify a whole bunch:
dostuff($_) if !$seen{$_};
and then in sub dostuff { my $key = shift; # do stuff $seen{$key}++; }
HTH :)
Lee.M - JupiterHost.Net
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>