raphael() wrote:
Hi,

Hello,

I want the below if loop to end if it cannot find any match & print the die
message.
However it just exit without hitting my "die"

As you can see in the code below I have tried many foolish ways to make the
script say
that it cannot find the number searched in while loop.

    while ( my $line = $FH->readline ) {
        chomp;

That should be:

          chomp $line;

Although from your code it looks like you don't really need to chomp() at all.


        next if ( $line =~ m/return/i );
        if ( $line =~ m/^$number\s+(\S+)\s+(.*)$/ ) {

             &get_info($number, $1, $2); # if ( $1, $2 ); # <-- don't

You shouldn't use an ampersand when you call a subroutine:

               get_info($number, $1, $2);


execute sub &get_info unless a match

             die "\nNo Entries Found By Number: [$number]\n" unless ($1);

$1 is captured from the pattern (\S+) so it will *always* be true unless the string it contains is '0' which is false.


                          # print $1; exit;

             last;
        }
    }
    $FH->close();

Any Ideas?



John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to