in reply to Re^3: Do not run code even if one element has matched exit code value
in thread Do not run code even if one element has matched exit code value

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

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

Replies are listed 'Best First'.
Re^5: Do not run code even if one element has matched exit code value
by AppleFritter (Vicar) on Mar 12, 2015 at 21:25 UTC

    For checking whether a list contains an element matching certain criteria or not, grep is a natural choice (natural for me, anyway). So if you merely need to know whether this retCode occurs, you could do this (based on toolic's script):

    #!/usr/bin/perl use strict; use warnings; use feature qw/say/; my @retCodes_values; while (<DATA>) { next unless /retCode\=/; chomp; my ($string, $exit_code) = split /retCode\=/, $_, 2; push @retCodes_values, [ $string, $exit_code ]; } if(grep { $_->[1] == 3 } @retCodes_values) { say "retCode=3 occurred!" } __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

    If you also need information on e.g. the associated log message, just save grep's result to another array.

      Thanks much :) This definitely helped me.