Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Best way to get all of the matches?

by prasadbabu (Prior)
on Sep 30, 2006 at 11:23 UTC ( #575662=note: print w/replies, xml ) Need Help??


in reply to Best way to get all of the matches?

I am not sure, something like this?

use strict; use warnings; my $file = 'match alphabets 21211 not numbers'; my $regexp = qr{[a-z]+}; $, ="\n"; print (my (@arr) = $file =~ /($regexp)/g );

Also avoid using, undef $/, for reading file like this, which ll affect your coding in some situations, instead try Perl Idioms Explained - my $string = do { local $/; <FILEHANDLE> };.

Prasad

Replies are listed 'Best First'.
Re^2: Best way to get all of the matches?
by GrandFather (Saint) on Sep 30, 2006 at 18:26 UTC

    print provides list context so the array is not required:

    ... print $file =~ /($regexp)/g;

    Prints:

    match alphabets not numbers

    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2023-04-01 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?