http://qs321.pair.com?node_id=575662


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