48 users online (1 members and 47 guests)  


  Results 1 to 2 of 2

Related

  1. Help with my perl script    Forum: CGI Perl Forum
    Replies: 1
  2. Please Help me (Perl Script)    Forum: CGI Perl Forum
    Replies: 1
  3. Executing the PERL CGI Script    Forum: CGI Perl Forum
    Replies: 1
  4. Perl script error..    Forum: CGI Perl Forum
    Replies: 1
  5. cgi script/perl problem    Forum: CGI Perl Forum
    Replies: 4
  1. #1
    danaevans's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2007
    Posts
    1

    Unhappy Meaning of dis perl script

    Code:
    perl -e  'while (<>)
    {
        print;
        $num = 2 if /fail_halt/i;
        $num = 1 if (/failure/i && ($num < 1));
    }
    print $num
    exit $num;'
    i dunno perl wanna know this meaning .. as this perl script has been embedded in an unix script

    help ASAP
    thank you
    Last edited by vinyl-junkie; 11-21-2007 at 11:25 AM. Reason: Added code tags

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: Meaning of dis perl script

    Hi,
    perl -e 'while (<>)
    -e
    , allows you to define Perl code to be executed by the compiler while looking at each line in the file.
    $num = 2 if /fail_halt/i;
    If a line contains fail_halt (the i ignores the case of fail_halt i.e. incase its FaIl_HaLt etc), then $num is given the value of "2".
    $num = 1 if (/failure/i && ($num < 1));
    Pretty much the same as above occurs except ($num < 1) checks if the first condition (above) has occured already, if it has then don't give $num the value of 1.
    print $num
    exit $num;
    Print the value of $num (either 1 or 2) then exit.
    This part could be better written as:
    $num = 2 if /fail_halt/i;
    $num = 1 if (/failure/i && ($num < 1));
    $num = 1 if /failure/i;
    $num = 2 if /fail_halt/i;
    assuming that $num wasn't given a value before this section of the script.
    Chris



Tags for this Thread