Plankton has asked for the wisdom of the Perl Monks concerning the following question:
... the output is ...#!/usr/bin/perl -w use strict; my $count1; my $count2; my $pat = "apple"; my @apples; while (<DATA>) { my $line = $_; @apples = grep /$pat/gi, $line; $count1 += @apples; @apples = m/$pat/gi; $count2 += @apples; } print "Count one is $count1\n"; print "Count two is $count2\n"; __DATA__ awna apple apple glais 16 Uriore Rd apple Highapplegate corner, VT. 4xyz59
Thanks!Count one is 3 Count two is 4
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: m// vs grep for counting occurances of a string
by wind (Priest) on Aug 11, 2007 at 01:22 UTC | |
Re: m// vs grep for counting occurances of a string
by GrandFather (Saint) on Aug 11, 2007 at 01:25 UTC | |
by Plankton (Vicar) on Aug 11, 2007 at 02:05 UTC | |
Re: m// vs grep for counting occurances of a string
by dogz007 (Scribe) on Aug 11, 2007 at 01:44 UTC | |
Re: m// vs grep for counting occurances of a string
by mreece (Friar) on Aug 11, 2007 at 05:28 UTC |