learningperl01 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { my $string_found = $_; my @match = ( $string_found =~ /(first_string|second_string|third_stri +ng|fourth_string|fifth_string)/gm ); print scalar @match," matches found: ",join ", ",@match, "\n"; } __DATA__ This is a test file matchme ljldjlfjd l;djfldjlf d test test test dljfldjlfjldjfldjlljdf one second_string dlfjldfj ljdfldjjf ldjfljdl dfljdlfj dfdlfj three ljfldjlj dlfjlasdj foiidufoiida matchdf dljfldsaofuoidfousdaof ladsjflasdof first_string dlfjodsuofuasdo sadoufosadu foasduf aosduf third_string __Current results__ 0 matches found: 1 matches found: second_string, 0 matches found: 0 matches found: 1 matches found: first_string, 1 matches found: third_string, __Wanted results__ 3 matches found: second_string, first_string, third_string
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing the count for regex matches
by Lawliet (Curate) on Mar 10, 2009 at 01:28 UTC | |
|
Re: Printing the count for regex matches
by bellaire (Hermit) on Mar 10, 2009 at 01:26 UTC | |
|
Re: Printing the count for regex matches
by jethro (Monsignor) on Mar 10, 2009 at 01:32 UTC | |
|
Re: Printing the count for regex matches
by hbm (Hermit) on Mar 10, 2009 at 01:41 UTC | |
by CountZero (Bishop) on Mar 10, 2009 at 05:49 UTC | |
|
Re: Printing the count for regex matches
by Marshall (Canon) on Mar 10, 2009 at 09:20 UTC | |
|
Re: Printing the count for regex matches
by johngg (Canon) on Mar 10, 2009 at 09:33 UTC |