Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

question about eval(bare word etc);

by xiaoyafeng (Chaplain)
on Feb 23, 2012 at 09:20 UTC ( #955678=perlquestion: print w/ replies, xml ) Need Help??
xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks

I'm stuck with transfering a gid pair using eval.

C:\>perl -MData::Dumper -e "$a = q([[gid, 0509b1300000000000BAB002]]); + print Dum per eval $a;" Bareword found where operator expected at (eval 1) line 1, near "0509b +1300000000 000BAB002" (Missing operator before b1300000000000BAB002?) $VAR1 = undef;

I found if I delete leading number of 2nd string, script works fine, but I don't know what I do wrong. Please help! TIA





I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Comment on question about eval(bare word etc);
Download Code
Re: question about eval(bare word etc);
by choroba (Abbot) on Feb 23, 2012 at 09:34 UTC
    What is 0509b1300000000000BAB002? Is it a string? Then it should be in quotes.
Re: question about eval(bare word etc);
by JavaFan (Canon) on Feb 23, 2012 at 10:12 UTC
    You are doing the equivalent of
    print Dumper [[gid, 0509b1300000000000BAB002]];
    Perl can make sense of the bare word gid (treating it as a string), but the 0509b1300000000000BAB002 gets it confused. It starts with what looks like a number, 0509, but b1300000000000BAB002 is not something that can follow a number in this context.

    Perhaps you meant

    $a = q([['gid', '0509b1300000000000BAB002']]);
      Thanks! script works when put the string into a pair of single quote. But I found this may not be the true cause to make the problem. actually, user put that string in double quote, and eval remove it in silence. Anyway, I realize eval input from users is very danger, it treat them with some extra actions background, and even it would be made use of by some ppl, though it looks a easy way to implement. I've changed the design and thus the question is going away .
Re: question about eval(bare word etc);
by sundialsvc4 (Abbot) on Feb 23, 2012 at 16:53 UTC
    That is good. You never want to 'eval' something that comes from an outside source. Not only do you not actually know if the data you're getting is actually the right answer, but also you are not really checking the file to see if it's formatted the way you thought it was. Programs ought to disbelieve their inputs, not blindly trust them. If there is a bug in whatever program produced that input file, your program should be the one to point out that the error exists and where; and it should recover graciously. A little more work up-front but worth it. (Let's face it: in a file of hundreds of thousands or even hundreds of millions of records, how else would you know? You wouldn't, of course.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://955678]
Approved by davies
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-12-27 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (177 votes), past polls