Monks,

I have a situation in which I want to search command output for lines containing any of a specified list of strings. I have scoured the net, Perl docs, and written the code below that is still not working. Can someone please help me understand where I am going wrong?

use constant { TRUE => 1, FALSE => 0 }; our $SUCCESS = 0; our %ErrorStrings = ( "No such file or directory" => TRUE, "does not exist in file" => TRUE, ); # Run command. @Output = qx { command here 2>&1 }; $RetCode1=$?; # If the return was success, we need to scan the output for errors. if ($RetCode1 == $SUCCESS) { # Scan the output and build a list of errors. my @FileErrors = grep { exists $ErrorStrings{$_} } @Output; if (@FileErrors) { $RetCode1 = scalar(@FileErrors); printf "Errors found: [%d] ", $RetCode1; push (@ProcErrors, @FileErrors); } # Non success error code. } else { printf "Error Code: [%d] ", $RetCode1; } # Output a status. printf "%-15s\n", ($RetCode1 == 0) ? "SUCCESS":"FAILED";

Which produces:

Processing A_Ra -> A/R ... SUCCESS Processing ADDRESS -> ADDRESS ... SUCCESS Processing ADJ-HIST -> ADJ-HIST ... SUCCESS Processing ALT-PN -> ALT-PN ... SUCCESS Processing AR-LEDGER -> AR-LEDGER ... SUCCESS Processing AR_LEVEL -> AR/LEVEL ... SUCCESS Processing BCBI -> BCBI ... SUCCESS Processing BID -> BID ... SUCCESS Processing BUDGET -> BUDGET ... SUCCESS Processing BUDGET_HEADER -> BUDGET/HEADER ... SUCCESS

And I have intentionally introduced an error into the command being called. What's more, the output of the command with the error is below:

'XORDER' does not exist in file. Open file error.

Please help me understand what I am doing wrong.

Thank you


In reply to Confusion with finding strings in command output by pgduke65

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.