Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

The tie()s That Bind

by KM (Priest)
on Jun 01, 2000 at 19:19 UTC ( #15838=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        tie VARIABLE, CLASSNAME, LIST
  2. or download this
        use Tie::Dir;
        tie %hash, Tie::Dir, "./";
    
  3. or download this
        TIEHASH classname, LIST
        DESTROY this
        FETCH this, key
    ...
        EXISTS this, key
        FIRSTKEY this
        NEXTKEY this, lastkey
    
  4. or download this
        TIEARRAY classname, LIST
        DESTROY this
        FETCH this, key
        STORE this, key, value
    
  5. or download this
        TIEHANDLE classname, LIST
        WRITE this, LIST
        PRINT this, LIST
    ...
        GETC this
        CLOSE this
        DESTROY this
    
  6. or download this
        # tie %hash, Tie::Dir, ".", DIR_UNLINK;
    
        sub TIEHASH {
    ...
            $unlink ||= 0;
            bless [$dir,undef,$unlink], $class;
        }
    
  7. or download this
        sub TIESCALAR {
            my $class = shift;
            my $name = shift;
    ...
    
            return bless \$city, $class;
        }
    
  8. or download this
        use Tie::getCity; # If the module name was Tie/getCity.pm
    
        tie($foo, 'Tie::getCity', $ENV{REMOTE_USER});
    
  9. or download this
        untie $foo;
  10. or download this
        package Example;
    
        use strict;
    ...
        sub Version {return $VERSION;}
    
        use Carp;
    
  11. or download this
        # Create tied hash
    
        sub TIEHASH {
    ...
    
            return bless $node => $self;
        }
    
  12. or download this
        $hash{FOO} = "bar";
  13. or download this
        # Store an entry
    
        sub STORE {
    ...
    
            if (!$id && !$passwd) {return 1;}
        }
    
  14. or download this
        $hash{name} = "";
    # or
        $hash{name} = undef;
    
  15. or download this
        if ($passwd eq "") {
            $cryptedPass = "";
        } else {
            $cryptedPass = crypt($passwd, $salt);
        }
    
  16. or download this
     
        # Warning, possible race condition ahead
        # I need to update this opening a locking!
    ...
            print FH "$Id\:$cryptedPass\n" unless $cryptedPass eq "";
            $foo = $hash{FOO};
        }
    
  17. or download this
        sub FETCH {
            my $self = shift;
            my $Id = shift;         
    ...
                return "$Id doesn't exist";
            }
        }
    
  18. or download this
        delete $hash{FOO};
  19. or download this
        sub DELETE {
            my $self = shift;
            my ($Id) = shift;
    ...
            close FH;
            return 1;
        }
    
  20. or download this
        %hash = "";
        %hash = %newHash;
        %hash = {};
        undef %hash;
    
  21. or download this
        sub CLEAR {
            my $self = shift;
            my ($passwdFile) = $self->{PATH};
    ...
            close FH;
            $self->{CURRENT} = {};
        }
    
  22. or download this
        sub FIRSTKEY {
            my $self = shift; 
            my $a = keys %{$self->{CURRENT}};
            each %{$self->{CURRENT}};
        }
    
  23. or download this
        sub NEXTKEY {
            my $self = shift;
            return each %{$self->{CURRENT}};
    
        }
    
  24. or download this
        sub DESTROY { unlink "/tmp/tie.txt";}
  25. or download this
        #!/usr/bin/perl
        use Example;
    
    ...
            if ($again !~ /y/i) { untie %hash; exit;}else{&ask;}
    
        }
    
  26. or download this
        tied(%hash)->newPwdFile('/usr/local/apache/.passwds');
  27. or download this
        $obj = tie(%hash, 'Tie::Class', 'rw');
        $obj->newPwdFile('/usr/local/apache/.passwds');
    
  28. or download this
        sub newPwdFile {
            my $self = shift;
            $self->{PATH} = @_ ? shift : die "No new file given";
    ...
            }
    
        }
    
  29. or download this
        # Usage: tie($VARIABLE,'TrackScalar', FILE, "\$VARIABLE name/descr
    +iption");
    
        # use TrackScalar;
    ...
        }
    
        1;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2014-11-20 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (102 votes), past polls