#1
  1. No Profile Picture
    chinnavi
    Guest
    Devshed Newbie (0 - 499 posts)
    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. #2
  3. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    Ft. Lauderdale, FL, US
    Posts
    29
    Rep 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.

IMN logo majestic logo threadwatch logo seochat tools logo