Hi Sunita,

Simplified the code to increase clarity

[code]
use strict;
use warnings;

while(<DATA>) {
chomp;
next if $. <= 3;
 my(undef, undef, undef, undef, undef, undef, $fail_count, undef) =
 m/^(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)$/;
 print '-' x 30, "\n";
print "SUMMARY\n";
print '-' x 30, "\n";
 if($fail_count > 0) {
print "Result: Fail\n";
} else {
print "Result: Pass\n";
}
}

__DATA__
U/A/S|Test|            Test           |Loop  | Run |Pass |Fail    |
 Arguments
         |                  Name         |Count|Count|Count|Count |
-----+----+---------------------------+-----+-----+-----+-----+--------------+---------------
         |  72| Traffic Test             |      1|      11|     11|
0| (none)
[/code]

[output]
------------------------------
SUMMARY
------------------------------
Result: Pass
[/output]

Here's how the regex works

(.+?) is a non greedy match which matches as few as possible.  In this
example the pipe symbol in regular expression is treated as alternation and
has to be escaped by backslash so that it will be interpreted as pipe
symbol. The anchors ^ (caret) and $ (dollar) is to define the position to
ensure that  whatever text we match is contained from the beginning of the
line to the end of the line.

As we are interested only for the fail count we set undef for the rest of
the captures. Finally we check if $fail_count is greater than zero and then
 we print Fail and else we print Pass

Hope it helps

[code]



On Mon, Jun 23, 2014 at 8:16 PM, Sunita Pradhan <
sunita.pradhan.2...@hotmail.com> wrote:

> Can you explain little bit , how this regex will work ?
>
> -Sunita
>
> ------------------------------
> Date: Mon, 23 Jun 2014 17:12:17 +0530
> Subject: Re: Need to Grep only fail count from the Pattern.
> From: shajiin...@gmail.com
> To: vernekaru...@gmail.com
> CC: beginners@perl.org
>
>
> Hi Uday,
>
> Here's one way to do it.
>
> [code]
> use strict;
> use warnings;
>
> while(<DATA>) {
> chomp;
>  next if $. <= 3;
>  my($uas, $test, $test_name, $loop_count, $run_count, $pass_count,
> $fail_count, $arguments) =
>  m/^(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)$/;
>  # my($uas, $test, $test_name, $loop_count, $run_count, $pass_count,
> $fail_count, $arguments);
>
> # if(m/^(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)\|(.+?)$/) {
> #
> #    $uas = $1;
> #    $test = $2;
> #    $test_name = $3;
> #    $loop_count = $4;
> #    $run_count = $5;
> #    $pass_count = $6;
> #    $fail_count = $7;
> #    $arguments = $8;
> # }
>  print "UAS : $uas\n";
> print "Test : $test\n";
> print "Test Name : $test_name\n";
>  print "Loop Count : $loop_count\n";
> print "Run Count : $run_count\n";
> print "Pass Count : $pass_count\n";
>  print "Fail Count : $fail_count\n";
> print "Arguments : $arguments\n";
>  print '-' x 30, "\n";
> print "SUMMARY\n";
> print '-' x 30, "\n";
>  if($fail_count > 0) {
> print "Result: Fail\n";
>  } else {
> print "Result: Pass\n";
> }
> }
> __DATA__
> U/A/S|Test|            Test           |Loop  | Run |Pass |Fail    |
>  Arguments
>          |                  Name         |Count|Count|Count|Count |
>
> -----+----+---------------------------+-----+-----+-----+-----+--------------+---------------
>          |  72| Traffic Test             |      1|      11|     11|
> 0| (none)
> [/code]
>
> [output]
> UAS :
> Test :   72
> Test Name :  Traffic Test
> Loop Count :       1
> Run Count :       11
> Pass Count :      11
> Fail Count :        0
> Arguments :  (none)
> ------------------------------
> SUMMARY
> ------------------------------
> Result: Pass
> [/output]
>
>
> On Mon, Jun 23, 2014 at 3:12 PM, Uday Vernekar <vernekaru...@gmail.com>
> wrote:
>
> Hi All,
>
>
> I have following Pattern from which I need to grep only the Fail count and
> store that in a variable.
>
> U/A/S|Test|            Test           |Loop  | Run |Pass |Fail    |
> Arguments
>          |                  Name         |Count|Count|Count|Count |
>
> -----+----+---------------------------+-----+-----+-----+-----+--------------+---------------
>          |  72| Traffic Test             |      1|      11|     11|
> 0| (none)
>
> based on fail count value need to print
>
> if 0------Sucess
> if >0------Fail
>
>
> with Regards
> Uday V G
>
> --
> *********************************************************
> Don't ask them WHY they hurt you,
> because all they'll tell you is lies and excuses.
>  Just know they were wrong, and try to move on.
> **********************************************************
>
>
>
>
> --
> best,
> Shaji
>
> ----------------------------------------------------------------------------------------------------------------------------------------------
> Your talent is God's gift to you. What you do with it is your gift back to
> God.
>
> ----------------------------------------------------------------------------------------------------------------------------------------------
>



-- 
best,
Shaji
----------------------------------------------------------------------------------------------------------------------------------------------
Your talent is God's gift to you. What you do with it is your gift back to
God.
----------------------------------------------------------------------------------------------------------------------------------------------

Reply via email to