Help! with dbmopen and hash evaluation Perl 5.002 
Author Message
 Help! with dbmopen and hash evaluation Perl 5.002

All,

I am new to perl and am trying to manage some files using dbmopen.  I
run something like this:

Quote:
>  dbmopen %HASH, "/path/filename", 0666;

Now, I would like to find out if there are any entries in this database,
and if not, show a message to that effect.  The O'Reilly book states
that, when evaluating a hash *in a scalar context*, it should return
false if there are no entries.  However, the code:

Quote:
>  unless ($HASH) {

        print "Nothing in database";
   } else {
        something else....
   }

doesn't work.  I also tried >>

unless (%HASH)
unless ($HASH == 0)
etc....

How can I make this test?  does this just not work with dbm?

Reply to e-mail or NG.
Thanks in advance,
Burris Jackes



Sun, 02 Jul 2000 03:00:00 GMT  
 Help! with dbmopen and hash evaluation Perl 5.002

Quote:

> The O'Reilly book states that, when evaluating a hash *in a scalar
> context*, it should return false if there are no entries.  However, the
> code:

> >  unless ($HASH) {

You're not using a hash there, that's a scalar called $HASH. This is
evaluating a hash in a scalar context:

    unless (%HASH) { ... }

Quote:
> I also tried >>

> unless (%HASH)

If that one doesn't work, you should file a bug report. Hope this helps!

--
Tom Phoenix           http://www.teleport.com/~rootbeer/

Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



Mon, 03 Jul 2000 03:00:00 GMT  
 Help! with dbmopen and hash evaluation Perl 5.002

This code:

  dbmopen %HASH, "blah", 0666;
  print "scalar HASH = ", scalar(%HASH), "\n";

seems to work fine.

However, I would recommend using scalar(keys %hash) to get the
size of a hash.  Using a hash name in a scalar context may well work
but it is not a common practice.

        -joseph
         http://www.effectiveperl.com

Quote:

> All,

> I am new to perl and am trying to manage some files using dbmopen.  I
> run something like this:

> >  dbmopen %HASH, "/path/filename", 0666;

> Now, I would like to find out if there are any entries in this database,
> and if not, show a message to that effect.[...]a



Mon, 03 Jul 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Module breaks in Perl 5.002 (Help!)

2. Help: Embedded Perl 5.002 Port DLL fails on Win95

3. Perl 5.002 socket call on DEC OSF/1 - HELP

4. socket problem with perl 5.002 - HELP!!!!

5. HELP: Perl 5.002, SunOS 5.5, gcc 2.7.2, dynamic loading

6. Help: Perl 5.002 installation on HP-UX 10.01

7. help compiling Perl 5.002 on Solaris2.4

8. Help - no Config.pm with perl 5.002

9. Perl 5.0 bug? dbmopen(), each(), and hash references

10. Help with perl hashes of hashes and arrays of hashes etc

11. perl 5.002 or perl 5.003

12. Multi-level hashes with dbmopen

 

 
Powered by phpBB® Forum Software