Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

grep all matches

by noviceuser (Novice)
on Apr 17, 2021 at 18:48 UTC ( #11131411=perlquestion: print w/replies, xml ) Need Help??

noviceuser has asked for the wisdom of the Perl Monks concerning the following question:

Below is code snippet where i am reading a log file and grepping the failed testcase, then if the failed testcase is also mentioned in the reference file (/icd/eps2/kaakash_p4/readSyntechScript/failedTest) then need to ignore testcase. But, i want to modify this code for more than 1 testcase, kindly help as i am new to perl

Note: utils commands are in-house package, please ignore

my $results = ''; my $cmd = "ls /icd/eps2/kaakash_p4/readSyntechScript/testsuites_re +port* | tail -1"; utils::execCommand(Command => $cmd, Results => \$results); chomp($results); my @reportContents = utils::getFileContents("$results"); my ($failedTest) = grep { /FAIL/ } @reportContents; $failedTest =~ /\|\s+(\w+)/g; my $failedTestsuite= $1; chomp ($failedTestsuite); print "Failed Testsuite = $failedTestsuite\n"; my $ignoreTestFile = "/icd/eps2/kaakash_p4/readSyntechScript/faile +dTest"; my @ignoreContents = utils::getFileContents("$ignoreTestFile"); my $referenceFailedTest = $ignoreContents[0]; chomp($referenceFailedTest); print "Reference Failed Testsuite = $referenceFailedTest\n"; if ("$failedTestsuite" eq "$referenceFailedTest") { print "ignore testcase"; }

2021-04-18 Retitled by Discipulus, as per Monastery guidelines

Replies are listed 'Best First'.
grep all matches
by hippo (Chancellor) on Apr 17, 2021 at 19:26 UTC

    Replace

    my ($failedTest) = grep { /FAIL/ } @reportContents; ...

    with

    for my $failedTest (grep { /FAIL/ } @reportContents) { ... }

    🦛

Re: grep all matches
by haukex (Bishop) on Apr 17, 2021 at 19:41 UTC

    Please see How do I compose an effective node title? and shorten your node title accordingly. Update: The janitors did it for you this time, but please keep this in mind! (The title was originally "Below is code snippet where i am reading a log file and grepping the failed testcase then, if the failed testcase is also found in the reference file (code in second code block) then we need to ignore.")

Re: grep all matches
by perlfan (Vicar) on Apr 17, 2021 at 22:40 UTC
    Tell me, did you find the max length of the "title" field?


    this comment intentional left blank after title normalization ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11131411]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-06-23 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (111 votes). Check out past polls.

    Notices?