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

Re: Returning N values from a Regexp

by thpfft (Chaplain)
on Nov 13, 2002 at 13:15 UTC ( [id://212580]=note: print w/replies, xml ) Need Help??


in reply to Returning N values from a Regexp

m// will return a list of matched (remembered) values if evaluated in list context. Your best bet would just be to gather the matches that way, then count them if you still need to.

my $text = 'foxcub ' x 1000; my @matches = $text =~ m/fox(\w+)/g; my $count = scalar @matches; print join(', ', @matches);

would print 'cub' 1000 times, in a comma-delimited list.

Log In?
Username:
Password:

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

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

    No recent polls found