in reply to Re: Invoke sub whose name is value of scalar
in thread Invoke sub whose name is value of scalar
There's usually better ways of achieving one's goals. We could help you better if we knew what you were actually trying to do.
I have used symbolic references to simulate linked lists. For example:
sub _create_node { my ($node,$parent,$node_info) = @_; no strict; @{$node}{qw/parent info/} = ($parent,$node_info); }
This way, each node is a hash with the name of its parent under the key "parent" and the info related to the node under the key "node_info". To go through a node:
sub go_through { no strict 'refs'; my ($self, $node) = @_; return "" unless defined ${$node}{"info"}; my @info_nodes; while (${$node}{"info"} ne "root"){ push @info_nodes, (${$node}{"info"}); $node = ${$node}{"parent"}; } return \@info_nodes; }
This runs very fast and doesn't need too much memory
citromatik
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Invoke sub whose name is value of scalar
by dragonchild (Archbishop) on Apr 14, 2008 at 13:55 UTC | |
by citromatik (Curate) on Apr 14, 2008 at 15:16 UTC | |
by dragonchild (Archbishop) on Apr 14, 2008 at 15:23 UTC | |
by citromatik (Curate) on Apr 14, 2008 at 15:58 UTC | |
by dragonchild (Archbishop) on Apr 14, 2008 at 16:02 UTC | |
| |
by Jenda (Abbot) on Apr 14, 2008 at 19:42 UTC |