Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: pattern matching

by Anonymous Monk
on Aug 21, 2002 at 11:53 UTC ( [id://191698]=note: print w/replies, xml ) Need Help??


in reply to Re: pattern matching
in thread pattern matching

Thanx again!:) Does the snippet work if there are more than one ID/P_ID in an array element?

Replies are listed 'Best First'.
Re: Re: Re: pattern matching
by physgreg (Scribe) on Aug 21, 2002 at 13:07 UTC
    If you want to act on more than one id then try
    while ($arrayElement =~ /:ID\s(\d*).*:P_ID\s(\d*)/g ) { print $1,$2,"\n"; # just an example }
    The /g gets all matches of the regex, so the captured bit ($1,$2) will be updated for each match in the while loop.
Re: Re: Re: pattern matching
by Basilides (Friar) on Aug 21, 2002 at 13:21 UTC
    For that, you'd want to use the global (/g) modifier on the end of your regex, and use the regex in a list context:
    @ids = m/:ID\s\d*/g

    You'll need to do another regex to pull the P_IDs,
    @p_ids = m/:P_ID\s\d*/g,
    and you won't be able to use backreferencing to ditch the ":ID " part.

    For that, I guess you could use another regex, or, if the data is regular, something like:
    for $i (0..$#ids) {$ids[Ģi] = substr ($ids[$i], 4);}

Re: Re: Re: pattern matching
by hotshot (Prior) on Aug 21, 2002 at 13:09 UTC
    No, you'll have to think a little here.

    Hotshot

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-19 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found