match expression then get data which follows...

Discussion in 'Perl Misc' started by Adam Sandler, Aug 2, 2005.

  1. Adam Sandler

    Adam Sandler Guest

    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!!!
     
    Adam Sandler, Aug 2, 2005
    #1
    1. Advertising

  2. 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
     
    John W. Krahn, Aug 2, 2005
    #2
    1. Advertising

  3. Adam Sandler

    Brian Wakem Guest

    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
     
    Brian Wakem, Aug 2, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mikey
    Replies:
    7
    Views:
    834
    Mikey
    Dec 12, 2003
  2. Girish
    Replies:
    1
    Views:
    956
    Fabien R
    Apr 14, 2005
  3. Hari
    Replies:
    3
    Views:
    418
    Edward Elliott
    May 12, 2006
  4. Replies:
    1
    Views:
    388
  5. Replies:
    0
    Views:
    336
Loading...

Share This Page