[BACK]Return to hash.pm CVS log [TXT][DIR] Up to [local] / wpscripts / ztransfer

Annotation of wpscripts/ztransfer/hash.pm, Revision 1.1

1.1     ! yason       1: #!/usr/bin/perl
        !             2: # $Id: hash.pm,v 1.1.2.1 2007/01/12 12:13:38 init Exp $
        !             3: package hash;
        !             4: use log;
        !             5: use warnings;
        !             6: use strict;
        !             7:
        !             8: our $HASHFILE = "/usr/local/etc/ztransfer.hash";
        !             9: our %directoryhash = ();
        !            10:
        !            11: sub loadtable()
        !            12: {
        !            13:     # read table from $HASHFILE (if any) into %directoryhash
        !            14:     # return number of records or return -1 on error
        !            15:     my @lines;
        !            16:     my @keys; #XXX
        !            17:     my $line;
        !            18:     my $lineno;        # for debug
        !            19:     my $key;
        !            20:     my $value;
        !            21:     my $records = 0;
        !            22:
        !            23:     open(FILE, "<$HASHFILE") or return (-1);
        !            24:
        !            25:     @lines = <FILE>;
        !            26:     foreach $line (@lines)
        !            27:     {
        !            28:        $lineno++;
        !            29:
        !            30:         # treat '#' ANYWHERE as invalid character leading to ignore whole line
        !            31:        # so it may be used as a comment
        !            32:        if ( ((index($line, '#', 0)) == -1) and $line ne "\n")
        !            33:        {
        !            34:            ($key, $value) = split(/\t+|\s+/, $line);
        !            35:            # avoid null elements
        !            36:            if ($value eq '')
        !            37:            {
        !            38:                return(0);
        !            39:            }
        !            40:
        !            41:            # don't count "\n"s
        !            42:            $records++;
        !            43:            $directoryhash{$key} = $value;
        !            44:        }
        !            45:     }
        !            46:     close(FILE);
        !            47:
        !            48:     return ($records);
        !            49: }
        !            50:
        !            51:
        !            52: sub lookup($)
        !            53: {
        !            54:     my $what = shift;
        !            55:
        !            56:     if ( defined($directoryhash{$what}) )
        !            57:     {
        !            58:        # return value for further substitution
        !            59:        return( $directoryhash{$what} );
        !            60:        # NOTREACHED
        !            61:     }
        !            62:     # else
        !            63:     return "";
        !            64: }
        !            65:
        !            66: return(1);

CVSweb