In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] (Ing. Branislav Gerzo) writes:
>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 ?

Ignoring precedence, which means that the last line is
evaluated as:

   ($seen{$item} ? $seen{$item}++ : $seen{$item}) = 1;

However, a far more standard and readable idiom would
be to write:

        $seen{$item}++;

which will have the effect you want.  For two reasons:
(1) An undefined value is numerically equivalent to zero;
(2) The postincrement operation on an undefined value is
special cased not to trigger the "use of uninitialized value"
warning precisely because this idiom is so useful (you do
have warnings enabled, don't you?).

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to