Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^4: while loop question

by adriang (Sexton)
on Aug 21, 2014 at 11:54 UTC ( [id://1098224]=note: print w/replies, xml ) Need Help??


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

"exisys" is not good for me at leat for this crrent problem because I use AnyDBM_File:

AnyDBM_File doesn't define an EXISTS method at /gd/Development/Perl/Pr +actice/www/cgi-bin/submitcoffee.pl line 32.

Replies are listed 'Best First'.
Re^5: while loop question
by SuicideJunkie (Vicar) on Aug 21, 2014 at 14:15 UTC

    "EXISTS", "exisys" and "exists" are all different words.

    exists is not a method. It is a basic built-in perl function. It is completely and utterly unrelated to AnyDBM_File. It tells you if a key exists in a hash; that is what you want, no need for looping.

    Read the documentation linked by aitap for details.

Re^5: while loop question
by aitap (Curate) on Aug 21, 2014 at 17:47 UTC

    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://1098224]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found