Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Inheritance in Hash

by Miguel (Friar)
on Apr 21, 2005 at 18:09 UTC ( #450134=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Inheritance in Hash
in thread Inheritance in Hash

You're right.

#!/usr/bin/perl -w use strict; my $data = { Colour => 'blue', Entries => { Flowers => { Dahlia => { Smell => 'nice' }, Rose => { Colour => 'red' } } } }; my $ref_flowers = $data->{Entries}->{Flowers}; my $colour = sub { my $flw=shift; $ref_flowers->{$flw}->{Colour} || $data->{Colour} }; print "Rose's color is ",$colour->('Rose'),"\n"; print "Dahlia's color is ", $colour->('Dahlia'),"\n"; __output__ Rose's color is Red. Dahlia's color is Blue.
Miguel


Comment on Re^3: Inheritance in Hash
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (15)
As of 2015-07-02 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (40 votes), past polls