CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
cmp equivalent

 



seema
New User

Dec 3, 2008, 11:06 PM

Post #1 of 2 (616 views)
cmp equivalent Can't Post

Hello Friends,
As used in the following context, to which one of the following operators is cmp equivalent?

Sample Code
my $line = <STDIN>;
chomp($line);
if (!$line cmp "Hello") {
print "What?\n";
}


Choice 1 (_) ge
Choice 2 (_) lt
Choice 3 (_) ne
Choice 4 (_) eq
Choice 5 (_) gt


KevinR
Veteran


Dec 3, 2008, 11:34 PM

Post #2 of 2 (615 views)
Re: [seema] cmp equivalent [In reply to] Can't Post

cmp acts like "lt-eq-gt" and returns a value depending on which of those conditions is true. The problem is that the code you posted appears to be wrong. The ! (not) operator is bound to $line and not to the return value of cmp. It probably should be written like this:


Code
if (!($line cmp "Hello")) {


So which choice do you think it is?
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives