Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 4th, 2001, 03:13 AM
chinnavi
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
hai ,
i wrote a simple program ... though i had over 24 months experience in perl.
This program behaves not as i expected
Anybody give me a thought:

vi if.pl
-----------------
use strict;

my $temp;

print " Enter Temperature : ";
$temp = <STDIN>;
if($temp <40)
{
print "n Normal n";
}
else
{
print "n Too Hot n";
}
~
~
~
~
------------

ChinnaVi $
ChinnaVi $
ChinnaVi $ perl if .pl
Can't open perl script "if": No such file or directory
ChinnaVi $ perl if.pl
Enter Temperature : 12

Normal
ChinnaVi $ perl if.pl
Enter Temperature : 56

Too Hot
ChinnaVi $ perl if.pl
Enter Temperature : as

Normal
ChinnaVi $


Why when i give "as" as Input Gives "Normal".

Thanks in Advance

vijay

Reply With Quote
  #2  
Old January 4th, 2001, 02:11 PM
luciddream luciddream is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: Ft. Lauderdale, FL, US
Posts: 29 luciddream User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i think your problem is that perl is evaluating the string as a number, and as id evaluating to < 40. so, you should validate the input if you want to make sure that you are getting numbers. also, i guess it didn't seem to be a problem for you, but, i would chomp() your variable from STDIN to make sure you dont have any n's or r's in your variable.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > whether perl or me mad?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT