Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: Symbolic references

by LanX (Chancellor)
on Apr 15, 2013 at 05:53 UTC ( #1028682=note: print w/replies, xml ) Need Help??

in reply to Re^2: Symbolic references
in thread Symbolic references

I've changed my code to be less terse and hopefully better understandable step by step.

> What if I may have a variable number of variables..

you can put a unlimited anount of elements into '$path' and it will work as long as the intermediate values really exist within the nested hashes (otherwise the result is undef).

> Is there a programatic way to read N variables into the reference?

??? what do you mean here with "reference"?

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^4: Symbolic references
by Anonymous Monk on Apr 15, 2013 at 06:57 UTC
    I used the wrong word 'reference' it should have been variable. I've tried to impliment your code below, but I'm still lost...
    foreach $argnum (0..$#ARGV){ print "$ARGV[$argnum]\n"; my $path=$ARGV[$argnum]; @path=split /\//,$path; $node=node->{$_} for @path; print $node; } print "\n"; }
      got it! phew!
      foreach $argnum (0..$#ARGV){ $node=$ret; print "$ARGV[$argnum]\n"; @path=split /\//,$ARGV[$argnum]; print Dumper @path; #debugging helps! $node=$node->{$_} for @path; print $node; } print "\n"; }
        Just a minor note: your way to iterate thru different arguments by index is rather cumbersome

        just do

        ~$ perl -E 'foreach $arg (@ARGV) { say split /\//,$arg }' 1/2 a/b/c 12 abc

        And plz consider using strict and warnings!

        Cheers Rolf

        ( addicted to the Perl Programming Language)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028682]
[GotToBTru]: Like most Swiss Army Knives, you can cut yourself trying to find the blade you actually want
[GotToBTru]: i am satisfied with the default settings turning the seemingly random formatting into something reliable
[Corion]: GotToBTru: Yeah, I started a quick(ly implemented but slowly running) implementation of a program that would guess the "best" configuration (that is, least amount of changes) from my code, but then found that it stops parsing the source as soon as it ..
[GotToBTru]: sadly, it can't do anything about this
[Corion]: ... encounters sub foo($bar,$baz) {, which is something I like nowadays
[Corion]: GotToBTru: Yeah, that stuff is hard to do away automatically ;)
[GotToBTru]: yeah, you mentioned it could not handle signatures

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2017-02-27 14:35 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (387 votes). Check out past polls.