Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Reading from memory location

by prashantpal84 (Initiate)
on Oct 31, 2012 at 07:15 UTC ( #1001613=perlquestion: print w/ replies, xml ) Need Help??
prashantpal84 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
my $var = {A => 1}; my $string = "$var"; print Dumper $string;
OP ---
$VAR1 = 'HASH(0x81b2818)';
Caught up in the scenario where we need to pull hash from string 'HASH(0x81b2818)'.

Comment on Reading from memory location
Select or Download Code
Re: Reading from memory location
by Happy-the-monk (Monsignor) on Oct 31, 2012 at 07:20 UTC

    $VAR1 = 'HASH(0x81b2818)';

    Try a backslash before the sigil: print Dumper \$string;

    Cheers, Sören

      Actually trying it might have been a good idea.

      >perl -wMstrict -MData::Dumper -le "my $var = {A => 1}; my $string = qq{$var}; print Dumper \$string; " $VAR1 = \'HASH(0x3cc06c)';
Re: Reading from memory location
by Anonymous Monk on Oct 31, 2012 at 07:21 UTC

    Caught up in the scenario where we need to pull hash from string 'HASH(0x81b2818)'.

    Sorry, but there is no such scenario

Re: Reading from memory location
by BrowserUk (Pope) on Oct 31, 2012 at 07:27 UTC

    Why have you stringified the hash reference in the first place?

    Whilst converting the string back to a hash reference is theoretically possible; it is difficult to do; and fraught with enough dangers that it should be avoided, even at great cost. And in general, it can be avoided without great cost.

    If you could explain why you are stringifying the reference in the first place, we can probably suggest alternatives that would avoid the problem.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    RIP Neil Armstrong

Re: Reading from memory location
by marquezc329 (Scribe) on Oct 31, 2012 at 07:32 UTC

    hello prashantpal84. In the future, your questions are more easily read if you enclose source in <code> tags.

    i.e.

    my $var = {A => 1}; my $string = "$var"; print Dumper $string;

    Output:

    $VAR1 = 'HASH(0x81b2818)'

Re: Reading from memory location
by Anonymous Monk on Oct 31, 2012 at 07:34 UTC
Re: Reading from memory location
by space_monk (Chaplain) on Oct 31, 2012 at 11:43 UTC

    Why don't you simply:

    use Data::Dumper; my $var = {A => 1}; print Dumper $var;

    Output:

    $VAR1 = { 'A' => 1 };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001613]
Approved by Happy-the-monk
help
Chatterbox?
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: (5)
As of 2014-12-27 03:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls