in reply to Re^2: elegant way of handling hash?
in thread elegant way of handling hash?

You can do the first two quite easily

@replacehash{ map{ "TEMP$_" } 1 .. 2 } = map{ $flow->$_ } qw[getExeName getTempName];

Doing the third one, with the double level of indirection, would probably require a string eval.

Whether you should do this is another matter entirely. It would have to be a pretty long list to warrent it, and even then you would probably be better having the $flow class provide an API that returned the hash. That way the construction need only be done once and the user of the $flow object can just do

my %replacehash = $flow->getAll();

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: elegant way of handling hash?
by Roy Johnson (Monsignor) on Jan 19, 2006 at 15:32 UTC
    It wouldn't need a string eval, but it does start to become convoluted. Something like this should work:
    @replacehash{ map{ "TEMP$_" } 1 .. 2 } = map{ use List::Util 'reduce'; reduce {$a->$b} ($flow, split /->/, $_); } qw[getExeName getTempName getData->getNameType];

    Caution: Contents may have been coded under pressure.