supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perlmonks,
I am a beginner in perl programming. I have used if-elsif-else conditional statement in my program to find the actual result. But I am getting errors in running the perl code. Can I get help from perl monks to correct the code so that I get correct result? Here, I know the values of $a, $b and $c and that $a is largest. But later on,I want to work with scalar variables whose values will be determined in the perl program. If I get correct result from this program, I shall try to set it in my bigger program. My objective is to find out which scalar variable out of three is the largest variable and then to do further calculations in each block as shown.
#!usr/bin/perl-w $a=0.9; $b=0.7; $c=0.5; if($a>$b>$c){print"\n$a is largest.\n";$x1=$b/$a;$x2=$c/$a;# Line 3 $x1r=sprintf("%.2f",$x1);$x2r=sprintf("%.2f",$x2); print"\n values are $x1r, $x2r"; } elsif($b>$c>$a){print"\n$b is largest.\n";$x3=$c/$b;$x2=$a/$b;# Line + 6 $x3r=sprintf("%.2f",$x3);$x4r=sprintf("%.2f",$x4); print"\n values are $x3r, $x4r"; } else($c>$a>$b){print"\n$c is largest.\n";$x5=$c/$b;$x6=$a/$b;# Line +9 $x5r=sprintf("%.2f",$x5);$x6r=sprintf("%.2f",$x6); print"\n values are $x5r, $x6r"; } exit;# Line 13
RESULTS Obtained:
Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\DR-SUPRIYO>cd desktop C:\Users\DR-SUPRIYO\Desktop>test.pl syntax error at C:\Users\DR-SUPRIYO\Desktop\test.pl line 3, near "$b>" syntax error at C:\Users\DR-SUPRIYO\Desktop\test.pl line 6, near "}" syntax error at C:\Users\DR-SUPRIYO\Desktop\test.pl line 9, near "}" syntax error at C:\Users\DR-SUPRIYO\Desktop\test.pl line 12, near "}" Execution of C:\Users\DR-SUPRIYO\Desktop\test.pl aborted due to compil +ation erro rs.
My Expected Result should look like this: 0.9 is largest. values are 0.78, 0.56
|
|---|