Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^5: while loop question

by aitap (Curate)
on Aug 21, 2014 at 17:47 UTC ( [id://1098253]=note: print w/replies, xml ) Need Help??


in reply to Re^4: while loop question
in thread while loop question

I can reproduce this error message: when I tie a hash using AnyDBM_File, it selects NDBM_File, which implements Tie::Hash without a sub EXISTS { ... }, so exists on the tied hash does not work.

However, defined replaces exists in this case, because NDBM_File cannot store an undef in the database:

#!/usr/bin/perl use Data::Dumper; use Fcntl; use AnyDBM_File; die $! unless tie %h, 'AnyDBM_File', 'test.db', O_RDWR()|O_CREAT(), 06 +00; undef $h{'b'}; # try to store an undef print Dumper(\%h); # empty string is stored instead print "still defined\n" if defined $h{'b'}; # we can confirm its existence: # if it's defined, it does exist # and no undefs exist there delete $h{'b'}; # delete works as expected print "does not exist\n" unless defined $h{'b'}; print Dumper(\%h); __END__ $VAR1 = { 'b' => '' }; still defined does not exist $VAR1 = {};
So using defined turns out to be the right decision.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1098253]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-03-28 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found