Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > match expression then get data which follows...

Reply
Thread Tools

match expression then get data which follows...

 
 
Adam Sandler
Guest
Posts: n/a
 
      08-02-2005
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!!!

 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      08-02-2005
Adam Sandler wrote:
>
> 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
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
 
Brian Wakem
Guest
Posts: n/a
 
      08-02-2005
Adam Sandler wrote:

> 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


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM
$match = true() for empty $match?? Victor XML 2 05-17-2004 10:43 AM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM



Advertisments