Oh my, of course it should be... my @repeated = grep { /some regex here/ && ++$seen{$_} > N } @source_array; ... to work properly.
-- iD 2011/12/30 Igor Dovgiy <ivd.pri...@gmail.com> > Hi Xi, > > You're looking only for 'p' letters, not D and O? Why? > > Anyway, generic solution will be something like... > > my %seen; > my @repeated = grep { /some regex here/ && $seen{$_} > N } @source_array; > > ... where N is how many times the symbols should appear in the source > array to be counted as duplicate. > and 'some regex' is, well, some regex to filter the symbols if needed. :) > > -- iD > > 2011/12/30 Xi Chen <cxde...@gmail.com> > >> Yes, I agree the code looks strange. Do you have any idea to do this >> with a clear code? I mean to find two same letters, "p" in @a? >> >> Xi >> >> On Thu, Dec 29, 2011 at 10:17 PM, John W. Krahn <jwkr...@shaw.ca> wrote: >> > Xi Chen wrote: >> >> >> >> Hello everyone, >> >> >> >> I saw a code below to get two same letters "p" in @a. >> >> >> >> @a = qw (D D p O H p A O); >> >> foreach $b (@a){ >> >> $n =~ /$b/i; >> >> if($n>= 2){ >> >> $m = $b; >> >> } >> >> } >> >> >> >> But I don't know what does ">=" mean. Thank you! >> > >> > >> > It means "greater than or equal to". The expression "$n >= 2" is true >> if >> > the value in $n is equal to 2 or is any value greater than 2, 6 for >> example. >> > If the value in $n is less than 2 then the expression is false. >> > >> > Your algorithm looks weird though because you are testing $n for the >> > presence of alphabetic characters (and then not using that information) >> and >> > then using $n in a numerical context. >> > >> > >> > >> > John >> > -- >> > Any intelligent fool can make things bigger and >> > more complex... It takes a touch of genius - >> > and a lot of courage to move in the opposite >> > direction. -- Albert Einstein >> > >> > -- >> > To unsubscribe, e-mail: beginners-unsubscr...@perl.org >> > For additional commands, e-mail: beginners-h...@perl.org >> > http://learn.perl.org/ >> > >> > >> >> -- >> To unsubscribe, e-mail: beginners-unsubscr...@perl.org >> For additional commands, e-mail: beginners-h...@perl.org >> http://learn.perl.org/ >> >> >> >