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

Re: Why am I getting wrong result in basic arithmetic calulations from d5.pl for $calculation1 and $calculation2?

by Cristoforo (Deacon)
on May 08, 2012 at 03:30 UTC ( #969360=note: print w/ replies, xml ) Need Help??


in reply to Why am I getting wrong result in basic arithmetic calculations from d5.pl for $calculation1 and $calculation2?

chromatic has found the cause of your problem, but just to show another way to initialize the %vals hash, here is a way that doesn't split but instead, captures the key/value pairs.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %vals = map /(\S+)\s*=\s*(\d+)/g, <DATA>; print Dumper \%vals; __DATA__ x1=2; x2=3; x3=4; y1=3; y2=5; y3=7; z1=4; z2=7; z3=10;

The output of Data::Dumper is

C:\Old_Data\perlp>perl t5.pl $VAR1 = { 'y1' => '3', 'z1' => '4', 'x2' => '3', 'z2' => '7', 'x1' => '2', 'x3' => '4', 'z3' => '10', 'y2' => '5', 'y3' => '7' };

Hope this is of some use, Chris


Comment on Re: Why am I getting wrong result in basic arithmetic calulations from d5.pl for $calculation1 and $calculation2?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-07-25 05:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls