Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Can a hash self reference?

by NetWallah (Canon)
on Jul 02, 2005 at 01:56 UTC ( #471857=note: print w/replies, xml ) Need Help??


in reply to Can a hash self reference?

You could get the results desired, if you delay their evaluation, and use slightly strange-looking syntax :
my %h; %hash = ( 1 => { ONE => 'testdir', TWO => 'tmpdir' }, 2 => { LOCATIONA => sub{ qq($hash{1}{ONE}/$hash{1}{TWO}/my_f +ile.txt)}, # Note - wrapped in "sub" LOCATIONB => sub{qq($hash{1}{TWO}/$hash{1}{ONE}/my_fi +le.txt)} } ); print $hash{2}{LOCATIONA}(),qq( = location a\n); #When called like a sub call, produces: # testdir/tmpdir/my_file.txt = location a
For complete consistency, you would probably wrap the values corresponding to ONE and TWO in sub's as well.

     "Income tax returns are the most imaginative fiction being written today." -- Herman Wouk

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2021-10-24 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?