Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: How to get a reference from an eval() string?

by choroba (Archbishop)
on Sep 06, 2016 at 09:36 UTC ( #1171238=note: print w/replies, xml ) Need Help??

in reply to How to get a reference from an eval() string?

Why don't you put the whole assignment to eval?
eval "$base\{$lastPart} = \$newData"

But you can return a reference to the value to be able to change it:

my $ref = eval "\\$base\{$lastPart}" || eval "$base = {}"; $$ref = $newData;

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: How to get a reference from an eval() string?
by exilepanda (Pilgrim) on Sep 06, 2016 at 10:15 UTC
    Oh! Stupid me... eval "$base\{$lastPart} = \$newData" This works!! BIG THANKS!!

    Seems my focus really draw to know how to get the reference deep in my heart.... rather than how to get this work done...

    But for the $$ref part, because I don't know what exactly the data type will be on the sub return side, either the assignment side, so that can be a %$ref, @$ref or $$ref etc. If I don't take care of it per case, I probably get sort of Not a XXXXX reference error.

      Beware the XY Problem. It's a common one in software fora.

        Confess that I might probably asking Y, but no regret. For resolving X, I believe TIMTOWTDI, and mostly for 1 time only. But Y is most likely a reusable skill in the long run (at least for me). Thanks for your echo though. =)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1171238]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2020-03-29 06:47 GMT
Find Nodes?
    Voting Booth?
    To "Disagree to disagree" means to:

    Results (169 votes). Check out past polls.