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

In reply to How can I change the perl program involving if-elsif-else conditional to get correct result? by supriyoch_2008

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.