|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > whether perl or me mad? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|