http://qs1969.pair.com?node_id=1014613


in reply to Re: Hash element exists/delete
in thread Hash element exists/delete

Can you tell me what I am doing wrong:

$ perl -e 'use strict; use warnings; my $one = 1; my $two = 2; if( $on +e = $two ) { print "True\n"; } else { print "False\n"; } ' True $

I get no warnings!

Replies are listed 'Best First'.
Re^3: Hash element exists/delete (= in conditional)
by LanX (Saint) on Jan 22, 2013 at 10:54 UTC
    Because it's valid code, $two could be a boolean to be tested and as a side-effect $one is set.

    try

    perl -e 'use strict; use warnings; my $one = 1; if( $one = 2 ) { prin +t "True\n"; } else { print "False\n"; } ' Found = in conditional, should be == at -e line 1. True

    or

    perl -we '$a=1; print (($a = 2) ? "True" : "False");' Found = in conditional, should be == at -e line 1.

    cause now it makes less sense.

    YMMV!

    Cheers Rolf

    UPDATE

    And personally I would be glad if this would cause a warning, too!

Re^3: Hash element exists/delete
by tobyink (Canon) on Jan 22, 2013 at 10:23 UTC

    Only warns in more complex conditionals...

    perl -we'if ($z=1 or $z=2) { 1 }'

    ... I'm not sure of the exact set of circumstances that triggers it.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name