Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Quick perl question

Quick perl question
Thread Tools
Jaey
Mac Elite
Join Date: Dec 2003
Status: Offline
Reply With Quote
Mar 9, 2004, 05:38 PM
 
I was writing a fairly long perl script, when I encountered a problem I never expected. I am somewhat new to perl, so this may seem pretty obvious to you guys, but here's my problem.
If you have:
Code:
$a=<>; if ($a==1) { print "hi\n"; }
and you enter '1' at the prompt, it prints out 'hi'.
But if you have:
Code:
$a=<>; if ($a eq 1) { print "hi\n"; }
It doesn't do anything. So what exactly am I missing?
     
Jaey  (op)
Mac Elite
Join Date: Dec 2003
Status: Offline
Reply With Quote
Mar 9, 2004, 06:39 PM
 
Heh, I feel stupid.
chomp $a;
     
Brass
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Mar 9, 2004, 07:32 PM
 
== is for a numerical comparison

eq is for a string comparison

The string "1\n" evaluates to the integer 1 (I think?). I think that using "==", almost any string would work with the exceptions of "" and "0", I think.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 04:43 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,