in reply to quick question about hash element access
Something like the following?
#!/usr/bin/perl -w use strict; my %test_hash; $test_hash{'a'}{'b'}{'c'}{'d'} = "Yay"; print get_id("a.b.c.d"), "\n"; sub get_id { my @parts = split /\./, $_[0]; # Currently written to access a global hash return $test_hash{$parts[0]}{$parts[1]}{$parts[2]}{$parts[3]}; }
I'm sure other monks can find more efficient (or bulletproof) ways. But this seems to work -- you could probably easily alter it so that it accepts a reference to a particular hash and uses that inside the sub.
Also note that $hash{'a'}{'b'}{'c'} is the same as $hash{'a'}->{'b'}->{'c'}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: quick question about hash element access
by argggh (Monk) on Jun 27, 2003 at 21:23 UTC | |
by argggh (Monk) on Jun 28, 2003 at 15:27 UTC | |
|
Re: Re: quick question about hash element access
by LanceDeeply (Chaplain) on Jun 27, 2003 at 21:28 UTC | |
by Nkuvu (Priest) on Jun 27, 2003 at 21:45 UTC | |
by LanceDeeply (Chaplain) on Jun 27, 2003 at 22:32 UTC | |
by argggh (Monk) on Jun 28, 2003 at 14:06 UTC | |
|
Re: Re: quick question about hash element access
by tilly (Archbishop) on Jun 27, 2003 at 21:21 UTC | |
by Nkuvu (Priest) on Jun 27, 2003 at 21:25 UTC |