On Tue, Jan 27, 2004 at 07:49:02AM -0800, Madhu Reddy ([EMAIL PROTECTED]) 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..
I'm not entirely sure what you are trying to do here but I'll take a stab at it. I'm assuming you have lines in a file or database like - "##I USBP 000001 10:38:09(000) <xyz_abc_etrack_validation,6> ETRACK_TOTAL_RECS : 100" "##I USBP 000002 12:38:09(000) <abc_gkkh_uiu,8> ETRACK_TOTAL_RECS : 500" You want to pull the last number from each of those lines and total them up. If that is the case then the following example may help you. If my example is what you're looking for and you need more explenation let me know. If it isn't what you are looking for, explain a little more about what you are trying to do and show us the code you have written. #!/usr/bin/perl use warnings; use strict; my $total_count; while(<DATA>) { $_ =~ /:\s+(\d+)/; $total_count += $1; } print "$total_count\n"; __DATA__ "##I USBP 000001 10:38:09(000) <xyz_abc_etrack_validation,6> ETRACK_TOTAL_RECS : 100" "##I USBP 000002 12:38:09(000) <abc_gkkh_uiu,8> ETRACK_TOTAL_RECS : 500" Kent -- A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila." Mitch Ratliffe -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>