CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
help with use all cells of array in regex

 



reverend
Novice

Dec 1, 2009, 6:22 PM

Post #1 of 2 (2946 views)
help with use all cells of array in regex Can't Post

I would like to count the number of occurrences where:
[comma or semicolon] followed by whitespace
precedes a string that matches an element in my array


Code
	$_ = join ' ',@wordmonger; 
$CC++ while (/[,;]\s+(~~@CoordinatingConjunctions)/g);


your help is much appreciated


(This post was edited by reverend on Dec 1, 2009, 6:40 PM)


7stud
Enthusiast

Dec 2, 2009, 5:06 PM

Post #2 of 2 (2900 views)
Re: [reverend] help with use all cells of array in regex [In reply to] Can't Post


Code
use strict; 
use warnings;
use 5.010;

my $str =<<ENDOFSTR;
hello, monkey
bye; monkey
bye, dog;

cat end
ENDOFSTR

my @arr = ('monkey', 'cat');
my $count = 0;

for (@arr) {
$count++ while ($str =~ /[,;]\s+$_/g) ;
}

say $count;

--output:--
3



(This post was edited by 7stud on Dec 2, 2009, 5:07 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives