in reply to Re: Going Backwards In Reference
in thread Going Backwards In Reference
sub addTo() { my $location = $_[0]; my $data = $_[1]; my @keys = split(/\//, $location); my $key; my $current = $database; while($key = shift(@keys)) { $current->{$key} = {} unless (exists $current->{$key} && ref($curr +ent->{$key}) eq "HASH"); $current = $current->{$key}; } #I AM STUCK HERE ----- $current = $data; }
This worked well, and actually changed the value it was referencing. However, when I tried to do the same referencing technique below with $current = $database, I would get stuck on the unless line, telling me that I didn't have a hash reference. The addTo method definitely works if I keep it as it now but switch the $current = $data code withmy $pointer = \$database->{"2002"}->{"Gustav"}->{"General"}->{"Overvie +w"}; ${$pointer} = "nasdfaull";
I would really like to make it work without having to switch that though.$current->{$key} = $data;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Going Backwards In Reference
by GrandFather (Saint) on Jul 12, 2007 at 22:13 UTC | |
by Spiffy (Initiate) on Jul 13, 2007 at 06:04 UTC |