Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Best way to get all of the matches?

by McDarren (Abbot)
on Sep 30, 2006 at 11:37 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2023-03-28 17:22 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (68 votes). Check out past polls.