in reply to Do not run code even if one element has matched exit code value

I am back again with probably a silly query.

Perhaps you meant to say simple query. There are no silly questions, just silly people. Or something like that. :)

Anyway, it's best to ask what you don't know. Otherwise, how will you (and the rest of us) ever learn?

  • Comment on Re: Do not run code even if one element has matched exit code value

Replies are listed 'Best First'.
Re^2: Do not run code even if one element has matched exit code value
by jayu_rao (Sexton) on Mar 12, 2015 at 15:31 UTC
    Thanks. Below is the snippet:
    my @retCodes_values; open my $read_log_file, '<', '/tmp/app.log' or die $!; while(<$read_log_file>){ next unless /retCode\=/; my ($string, $exit_code) = split /retCode\=/,$_,2; push @retCodes_values, [ $string, $exit_code ]; } foreach(@retCodes_values) { if ($_!=~3) { read 2nd log file; read 3rd log file; } }

    ____app.log______

    15288 :: Mon Mar 2 13:23:32 2015::App.pm:status returned with retCode=1

    15288 :: Mon Mar 2 13:24:32 2015::App.pm:status returned with retCode=3

    15288 :: Mon Mar 2 13:25:32 2015::App.pm:status returned with retCode=4

    15288 :: Mon Mar 2 13:23:32 2015::App.pm:status returned with retCode=5

      The main issue is that you are creating an array of arrays, which you then need to dereference:
      use warnings; use strict; my @retCodes_values; while (<DATA>) { next unless /retCode\=/; chomp; my ( $string, $exit_code ) = split /retCode\=/, $_, 2; push @retCodes_values, [ $string, $exit_code ]; } for my $aref (@retCodes_values) { if ($aref->[1] != 3) { print "@{ $aref }\n"; } } __DATA__ 15288 :: Mon Mar 2 13:23:32 2015::App.pm:status returned with retCode= +1 15288 :: Mon Mar 2 13:24:32 2015::App.pm:status returned with retCode= +3 15288 :: Mon Mar 2 13:25:32 2015::App.pm:status returned with retCode= +4 15288 :: Mon Mar 2 13:23:32 2015::App.pm:status returned with retCode= +5

      Outputs:

      15288 :: Mon Mar 2 13:23:32 2015::App.pm:status returned with 1 15288 :: Mon Mar 2 13:25:32 2015::App.pm:status returned with 4 15288 :: Mon Mar 2 13:23:32 2015::App.pm:status returned with 5

      See also:

        Thanks. How do I loop to check all lines for an existence of 3.

        It could occur in any line number of the log file and not necessarily at $aref->1. I'll have to read more about array of arrays.

        Regards,

        Jay

      Your snippet is not fully functional. Give a minute to clean it up: Never mind, toolic is way ahead of me.

      #!/usr/bin/perl use strict; my @retCodes_values; open my $read_log_file, '<', '/tmp/app.log' or die $!; while(<$read_log_file>){ next unless /retCode\=/; my ($string, $exit_code) = split /retCode\=/,$_,2; push @retCodes_values, [ $string, $exit_code ]; } foreach(@retCodes_values) { if ($_!=~3) { read 2nd log file; read 3rd log file; } } exit; __END__ D:\PerlMonks>test2.pl Bareword found where operator expected at D:\PerlMonks\test2.pl line 1 +9, near "2nd" (Missing operator before nd?) Bareword found where operator expected at D:\PerlMonks\test2.pl line 2 +0, near "3rd" (Missing operator before rd?) Not enough arguments for read at D:\PerlMonks\test2.pl line 19, near " +2nd " syntax error at D:\PerlMonks\test2.pl line 19, near "2nd " Not enough arguments for read at D:\PerlMonks\test2.pl line 20, near " +3rd " syntax error at D:\PerlMonks\test2.pl line 20, near "3rd " Execution of D:\PerlMonks\test2.pl aborted due to compilation errors.