Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.2 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    Tie::Hash::Layered 0.9

    Download button

    No screenshots available
    Downloads: 216  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Simon Wistow | More programs
    Perl Artistic License / FREE
    March 24th, 2010, 03:55 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    Tie::Hash::Layered description

    Perl extension for layerable hash values

    Tie::Hash::Layered is a Perl module that lets you layer hashes on top of each other opaquely so that top most layers obscure bottom ones.

    Think of it like sheets of OHP transparencies, if a value is set in a top and bottom layer then that's you when you access that key you get the value from the top layer but if you access something not set in the top layer but set in the bottom layer then you get the value from the bottom layer ...

    ... and breathe.

    In short :

    Tied Hash : foo=>'bob' , quux=>'fleeg' | | ^ | Layer 1 : foo=>'bob' ^ Layer 2 : foo=>'bar' , quux=>'fleeg'


    So why is this useful? Well, the obvious application is for preferences. In a CGI app you could tie in the bottom most hash to a database with default all-users' preferences, the second layer with the current user's preferences, the layer above that with the per-session preferences and the layer above that with the per-request values.

    SYNOPSIS

     use Tie::Hash::Layered;
     

     my %hash;
     my %test1 = ( foo => 'bar', bob => 'sprite' );
     my %test2 = ( bob => 'joey');

     # tie the new hash with the initialised hashes above
     tie %hash, 'Tie::Hash::Layered', (\%test1, \%test2);

     # because the hash values are layered
     # left to right is bottom to top so ...
     # $hash{'bob'} eq 'joey'
     # $hash{'foo'} eq 'bar'
     # ... which is pretty cool

     $hash{'foo'} = 'flam';
     # this sets 'foo' in the top most layer so ...
     # $hash{'foo'} now eq 'flam'

     delete $hash{'bob'};

     # this deletes $hash{'bob'} in the top layer so ...
     # $hash{'bob'} now eq 'sprite'

     # let's clear the hash
     %hash = ();

     # which clears the top layer so that ..
     # $hash{'foo'} now eq 'bar'

     # set foo and quux in the top layer
     $hash{'foo'} = 'flam';
     $hash{'quux'} = 'fleeg';
     
     # the keys of %hash are now ...
     # foo, bob and quux notice the lack of duplicates
     
     # setting mutt in the bottom later hash ...
     $test1{'mutt'} = 'ley';
     # ... also sets it in %hash
     # so $hash{'mutt'} eq 'ley'

     $test2{'mutt'} = 'mail';
     # and $hash{'mutt'} now eq 'mail'

     # you can access the stack of hashes
     # like a normal array ...
     
     tied(%hash}->push( { slub => 'slob' } );
     # $hash{'slub'} eq 'slob'

     tied(%hash)->unshift( { slub => 'slab' } );
     # $hash{'slub'} eq 'slab'

     tied(%hash}->shift();
     # $hash{'slub'} eq 'slob'

     tied(%hash)->pop();
     # $hash{'slub'} is now not defined



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    hash values | Perl module | layered | hash | values

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM