in reply to Determining if an element in a list
use warnings; use strict; my $pattern = '1'; my @list = ( 1,2,'a','b',5,1,1,'t'); # In a scalar context grep will return the total times # that the +pattern was find in @list # If you use @times = grep(/$pattern/,@list); # @times will contain the pattern it founds in the array # in this case @times will be ( 1 , 1 , 1 ) my $times = grep(/$pattern/,@list); print "The pattern was found $times times";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Determining if an element in a list
by davorg (Chancellor) on Sep 13, 2001 at 12:39 UTC |