Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: regular expression help

by Perlbotics (Archbishop)
on Jun 03, 2009 at 20:01 UTC ( [id://768142]=note: print w/replies, xml ) Need Help??


in reply to regular expression help

Hi, if I understand your question correct, you want to extract information from each token. So splitting the string into tokens first and then extracting any useful information one by one might be a suitable approach for you?

use strict; sub extract { chomp(my $orig = shift); foreach ( split(/,/, $orig) ) { # scan list of tokens if ( / <\*\d+> ([^<]+) < (\d+) : (\d+) > /x ) { # do something with extracted information print "got $1/$2/$3 from '$orig'\n"; } } } extract($_) while (<DATA>); __DATA__ <*2>H<3:0>,<*2>I<3:0>,...,<*2>Z<2:0> H<3:0>,<*2>I<3:0>,...,<*2>Z<2:0>
Prints:
got H/3/0 from '<*2>H<3:0>,<*2>I<3:0>,...,<*2>Z<2:0>' got I/3/0 from '<*2>H<3:0>,<*2>I<3:0>,...,<*2>Z<2:0>' got Z/2/0 from '<*2>H<3:0>,<*2>I<3:0>,...,<*2>Z<2:0>' got I/3/0 from 'H<3:0>,<*2>I<3:0>,...,<*2>Z<2:0>' got Z/2/0 from 'H<3:0>,<*2>I<3:0>,...,<*2>Z<2:0>'

Replies are listed 'Best First'.
Re^2: regular expression help
by pip9ball (Acolyte) on Jun 04, 2009 at 14:41 UTC
    I like this approach and will see if I can restructure my code a bit to be able to do this. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://768142]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-25 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found