Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: How to interpret a string as perl code and execute it?

by Corion (Pope)
on Feb 05, 2011 at 17:12 UTC ( #886423=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to interpret a string as perl code and execute it?
in thread How to interpret a string as perl code and execute it?

Would your code work when run stand-alone? Have you printed out the code you're trying to eval? Have you looked at the error message and looked at what causes it?

The following change to your code might help you see the problem:

use diagnostics; use warnings; use strict; use Data::Dumper; my %h; $h{ 'a' }{ 'b' } = 5; my $b_code =<<'CODE'; sub tryme_b { my $foo = shift; return ${ $foo }{ 'a' }{ 'b' }; } CODE my $c = "$b_code; tryme_b( \%h );"; my $ans = eval $c or die "[$c] doesn't work:$@"; print "b:$ans,\n";

Also, basic debugging in your tryme_b would also show you what goes wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://886423]
help
Chatterbox?
[marto]: good morning all
[Corion]: Hi marto!
[Corion]: Oooh - finally, I can say no lazy; :)
[Corion]: But it's another The::Net incarnation, too sad ;)

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2018-07-17 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (358 votes). Check out past polls.

    Notices?