Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have some code (that works :) ), but it just doesn't feel like the "perl" way to get it done. Can anyone suggest a more elegant way (like putting all of the matches into a variable and only executing the print statement once)?
#!/usr/bin/perl -w use strict; my $regexp = qr{some regexp}o; open (FILE, 'some.file') or die "Can't open file.\n"; undef $/; my $file = <FILE>; close FILE; while ($file =~ /$regexp/g) { print "$1\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Best way to get all of the matches?
by prasadbabu (Prior) on Sep 30, 2006 at 11:23 UTC | |
by GrandFather (Saint) on Sep 30, 2006 at 18:26 UTC | |
Re: Best way to get all of the matches?
by McDarren (Abbot) on Sep 30, 2006 at 11:37 UTC | |
Re: Best way to get all of the matches?
by fmerges (Chaplain) on Sep 30, 2006 at 14:56 UTC | |
Re: Best way to get all of the matches?
by explorer (Chaplain) on Sep 30, 2006 at 11:21 UTC |
Back to
Seekers of Perl Wisdom