Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Chomp a numerical expression, return the answer.

by Trix606 (Monk)
on May 18, 2006 at 15:23 UTC ( #550256=note: print w/ replies, xml ) Need Help??


in reply to Chomp a numerical expression, return the answer.

Try this:

chomp($exp = <STDIN>); $out = eval $exp; print $out, "\n";
UPDATE: As blazar points out, while this code does what you want, know that it will blissfully run any valid Perl command. You might add some editing of your input before handing it to eval.

Good Luck,

Trix


Comment on Re: Chomp a numerical expression, return the answer.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2015-07-04 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls