Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help with relational operators in PERL!!

Status
Not open for further replies.

Sumitha Sudhakaran

Junior Member level 2
Joined
Aug 7, 2012
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Bangalore
Activity points
1,440
I want to compare 2 multi digit numbers, say $x = 99 and $y = 158.. the operation: if ($x gt $y)
{print $x;}

the result gives 99 as the answer.. Probably because 9 is greater than 1.. Wats the command to get the correct answer in PERL???
 

The problem is you are using the wrong relational operator. "gt" is for comparing two strings. For example,

Code:
$string1 = 'cat';
$string2 = 'dog';

    if ($string1 ne $string2) {
        print "Not equal\n";
    } else {
        print "Equal\n";
    }

You need to use < or > for integers.
Code:
$x = 99;
$y = 158;

if ($x > $y){
print $x;
} else {
print "Not greater than";
}

Hope this helps
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top