match expression then get data which follows...

A

Adam Sandler

Hello,

I have a question about capturing the data which appears after matching
a pattern. I have a report which has more than one "quantity:
xxx,yyy,zzz" entry (where xxx,yyy,zzz are integers grouped together).
Based on prvious experience, I know how to find all the instances of
"quantity:" but how do I get the integers which follow into a variable
(I want to add up all the values later)??? The only similar experience
I have is in java I can use indexOf to find the poisiton of the first
number and parse from there... does Perl have an equivalent? Examples,
insight, advice is greatly appreciated.

Thanks!!!
 
J

John W. Krahn

Adam said:
I have a question about capturing the data which appears after matching
a pattern. I have a report which has more than one "quantity:
xxx,yyy,zzz" entry (where xxx,yyy,zzz are integers grouped together).
Based on prvious experience, I know how to find all the instances of
"quantity:" but how do I get the integers which follow into a variable
(I want to add up all the values later)??? The only similar experience
I have is in java I can use indexOf to find the poisiton of the first
number and parse from there... does Perl have an equivalent? Examples,
insight, advice is greatly appreciated.

Perhaps something like:

my @quantities = $data =~ /quantity:\s*([\d,]+)/;


John
 
B

Brian Wakem

Adam said:
Hello,

I have a question about capturing the data which appears after matching
a pattern. I have a report which has more than one "quantity:
xxx,yyy,zzz" entry (where xxx,yyy,zzz are integers grouped together).
Based on prvious experience, I know how to find all the instances of
"quantity:" but how do I get the integers which follow into a variable
(I want to add up all the values later)??? The only similar experience
I have is in java I can use indexOf to find the poisiton of the first
number and parse from there... does Perl have an equivalent? Examples,
insight, advice is greatly appreciated.

Thanks!!!


perldoc -f pos
perldoc -f substr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top