Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^3: Creating flexible method accessor

by puterboy (Scribe)
on Feb 02, 2014 at 02:53 UTC ( #1073021=note: print w/replies, xml ) Need Help??

in reply to Re^2: Creating flexible method accessor
in thread Creating flexible method accessor

Disregard #4. I misread what you wrote. It works fine.
  • Comment on Re^3: Creating flexible method accessor

Replies are listed 'Best First'.
Re^4: Creating flexible method accessor
by puterboy (Scribe) on Feb 02, 2014 at 03:04 UTC
    Actually, to clarify -- your suggestion of using ${path} works fine when applied to my original script which allows the multi-level hierarchies I need.

    However, it is not obvious (to me) how to make this work in your non-eval script. If I use ${path}, I get all sorts of errors.

    Unfortunately, the exercise you leave to the reader is actually the exercise that was the point of my original question :) (though I quite appreciate your provided script).

      ${path} is really just a different way of writing $path:

      my $foo = "xyz"; print $foo."bar"; # prints "xyzbar" print "${foo}bar"; # same

      As for making it more flexible: let's say you've got your "path" in an array @path, one way to walk your data structure is: $self = $self->{$_} for @path;

        The problem with 'walking the path' is that there is no guarantee that the path will be: ->{hash1}->{hash2}->{hash3}
        It could be any combination of hashes, hashrefs, arrays, arrayrefs -- which is why I wanted to pass a *string* rather than a list (array) of hash keys.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1073021]
[shmem]: in the french alpes, at the end of a gravel road, we had a beer at a hut - and heard an enduro coming up.
[shmem]: not by the road, but from there below where you wouldn't want to walk.
[shmem]: the biker stopped the machine at the table and took off his helmet.
[shmem]: long white hair, long beard the same, then he proceeded to get off the bike
[shmem]: saying "biking itself isn't that much, but getting up and down - hell!"
[shmem]: up and down: on and off the bike, of course

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2017-06-25 20:10 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (570 votes). Check out past polls.