[ale] OT: perl dbm files?

Robert L. Harris nomad at rnd-consulting.com
Fri Nov 19 12:02:22 EST 1999


Yeah, I found this about an hour later after a 30min break and
a coke...  Gotta stop typing when I get tired...
Actually, I use T/F for $Verbose because of another
section.  I'm also considering having $Verbose be a
threshold (sp?) instead of just a T/F... Good idea
for another variable I have set..

Thanks... 
  Robert
Thus spake Mike Fletcher (fletch at phydeaux.org):

> 
> 
> 01:  foreach $Directory (@DoDirs) {
> 02:    print "  \$Directory :$Directory:\n" if ($Verbose eq "T");
> 03:    unlink($DB);
> 04:    umask(0377);
> 05:    $DB="$Directory"."/"."$DBFile";
> 06:    print "  \$DB :$DB:\n" if ($Verbose eq "T");
> 07:    tie(%KnownGood, 'DB_File', $DB) or die "Can't open DB_File $DB : $!\n";
> 08:
> 09:    %KnownGood=&GetDirStats($Directory);
> 10:
> 11:    print "  Print File:\n" if ($Verbose eq "T");
> 12:    foreach $Key (keys %KnownGood) {
> 13:      print "    \$KnownGood{$Key} :$KnownGood{$Key}:\n" if ($Verbose eq "T");
> 14:    }
> 15:
> 16:    untie(%KnownGood);
> 17:  }
> ----------------------------------------------------
> 
>     Robert> The print of the HASH looks good, but it doesn't even
>     Robert> create $DB and it doesn't die.  Thoughts?
> 
>         It does create $DB, but since on line 3 you have `unlink($DB)' 
> before you set $DB on line 5 you're removing the previous loop's file
> each time through.  Chances are that you've got one file left in
> whatever directory happens to be the last in @DoDirs.
> 
>         So swap line 5 up before line 3 (and you could rewrite it a
> bit more clearly as `$DB = "$Directory/$DBFile";' in the process :).
> 
>         And the `if ($Verbose eq "T")' could be written more
> succinctly as `if $Verbose' (assuming you start off with setting
> `$Verbose = undef;' in the case you don't want verbose output).
> 
> -- 
> Fletch                | "If you find my answers frightening,       __`'/|
> fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
> 678 443-6239(w)       |  scary questions." -- Jules                =(___)=
>                       |                                               U

---------------------------------------------------------------------------
Robert L. Harris                |   "A person is smart;
Senior System Engineer          |        People are dumb, panicky
  R&D Consulting.               \_            dangerous animals"  - Agent K  


http://www.rnd-consulting.com/~nomad

DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.

FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'






More information about the Ale mailing list