Ing. Branislav Gerzo <[EMAIL PROTECTED]> wrote: : Hi [EMAIL PROTECTED], : : I have code snippet, which gave me statistics of lines in file: : : foreach my $item (@list) { : chomp($item); : if ($seen{$item}) { : $seen{$item}++; : } else { : $seen{$item} = 1; : } : } : : this is quite simple, so I rewrite that as: : : foreach my $item (@list) { : chomp($item); : $seen{$item} ? $seen{$item}++ : $seen{$item} = 1; } : : and perl says: : : Can't modify postincrement (++) in scalar assignment ... : : What I am doing bad?
$seen{$item} = $seen{$item} ? ++$seen{$item} : 1; TIMTOWTDI: chomp @list; foreach my $item (@list) { if ($seen{$item}) { $seen{$item}++; } else { $seen{$item} = 1; } } # ---------- chomp @list; foreach my $item (@list) { $seen{ $item }++; } # ---------- chomp @list; $seen{ $_ }++ foreach @list; HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>