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