Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Hash element exists/delete

by rovf (Priest)
on Jan 22, 2013 at 08:53 UTC ( #1014603=note: print w/replies, xml ) Need Help??


in reply to Hash element exists/delete

Adding to what ree already pointed out: If you would have used use warnings; in your code, Perl would have told you about the problem.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: Hash element exists/delete
by tmharish (Friar) on Jan 22, 2013 at 09:58 UTC

    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!

      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!

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014603]
help
Chatterbox?
[marto]: good morning all
[Discipulus]: mmh.. why print eval '2+1/3*(2+2/5))' does not print anything?

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-10-24 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (287 votes). Check out past polls.

    Notices?