Madhu Reddy wrote:

> Hi,
>    I need some help on regular expression...
> i have following in variable $total_count
>
> $total_count = "##I USBP 000001 10:38:09(000)
> <xyz_abc_etrack_validation,6> ETRACK_TOTAL_RECS : 100"
>
> Here in this ETRACK_TOTAL_RECS is fixed and common for
> all and rest is changing...
>
> like following
>
> $total_count = "##I USBP 000002 12:38:09(000)
> <abc_gkkh_uiu,8> ETRACK_TOTAL_RECS : 500"
>
>
> here i need some regular expression to get, 100 like
> following
>
> $total_count = 100
>
> I appreciate u r help..

Hi Madhu.

There are two separate things that regexes are good for:
verifying that a string matches a given pattern, and
extracting pieces of data from the string. Usually you want
a mixture of both at the same time. Code looking something
like this should do what you want:

  if ($total_count =~ m/\sETRACK_TOTAL_RECS\s*:\s*(\d+)/) {

    my $total_recs = $1;
    print "ETRACK_TOTAL_RECS = $total_recs\n";
  }
  else {

    die "Unexpected record format: $total_count";
  }

But there are endless variations depending on how much checking
you want to build in.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to