Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: '+' to +

by ambrus (Abbot)
on May 30, 2005 at 08:24 UTC ( [id://461706]=note: print w/replies, xml ) Need Help??


in reply to '+' to +

This one involves a bit of magic, but it does not use eval, nor does it explicitly list the four operators.

use Math::BigFloat; $big = Math::BigFloat->bzero; $Problem = "12 - 5"; $Problem =~ /^(\d+)\s(\S)\s(\d+)$/; ($Number1, $Operator, $Number2) = +($1, $2, $3); $Answer = ($big + $Number1)->${\("(" . $Operator)}($Number2); print $Answer, "\n";

Replies are listed 'Best First'.
Re^2: '+' to +
by ambrus (Abbot) on May 30, 2005 at 20:54 UTC

    The same idea, except that it's a bit faster, still using only core modules.

    use Math::Complex; $big = 0*i; $Problem = "6 * 8"; $Problem =~ /^(\d+)\s(\S)\s(\d+)$/; ($Number1, $Operator, $Number2) = +($1, $2, $3); $Answer = ($big + $Number1)->${\("(" . $Operator)}($Number2); print $Answer, "\n";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-18 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found