Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Best way to get all of the matches?

by McDarren (Abbot)
on Sep 30, 2006 at 11:37 UTC ( [id://575663]=note: print w/replies, xml ) Need Help??


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

Here is an example that demonstrates how I would approach something like this:
cat foo.txt fred barney betty wilma dino george jane elmo judy #!/usr/bin/perl -wl use strict; # Pull out all those words containg the letter e my $file = 'foo.txt'; open my $fh, '<', $file or die "Cannot open $file:$!"; my @matches; while (my $line = <$fh>) { chomp($line); my @wanted = $line =~ m/\b(\w*?e\w*?)\b/g; push @matches, @wanted; } print for @matches;
Which prints..
fred barney betty george jane elmo

Hope this heps,
Darren :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 10:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found