Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Grep reutrn the occurance of a pattern

by moklevat (Priest)
on Mar 13, 2008 at 13:56 UTC ( #673967=note: print w/replies, xml ) Need Help??


in reply to Grep reutrn the occurance of a pattern

To get the number of matches you evaluate grep in scalar context. Here:

#!/usr/bin/perl use strict; use warnings; my @items = qw/yes no no no yes yes no no/; my $number_of_matches = grep(/yes/,@items); print "$number_of_matches\n";

Prints 3.

Update: Noticed that I left out @items, and I see I am not alone in my confusion about exactly what it was the OP wanted.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://673967]
help
Chatterbox?
[virtualsue]: weird. my p6 simple web spider fails to extract anchor tags from perlmonks.org
[holli]: Nice. Turns out I don't have to remove Sweet home Alabama from my playlist ;)
[Corion]: virtualsue: We have some links with a newline between <a and the attributes, maybe your extractor fails to handle that?
[virtualsue]: It's not getting any at all, which seems quite broken
virtualsue upgrades modules
[erix]: aka *falling forward*

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2017-12-13 11:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (360 votes). Check out past polls.

    Notices?