"Merrychristmas!" wrote:
>  
> 1.    @array = qw ( hello world hello how are you );
> 2.    $match = 'HEllo';
> 3.    print "Your search for $match returns $subroutine $count
> records<br>\n";
> 
> $subroutine = &count;
> sub count {
>         foreach $record (@array){
>                  if (grep /$match/i, $record) {
>                     print $record;
>                     $count++;
>                 };
>         };
> };

There's another problem in it.
Usually the grep function is used in the form
grep  subroutine  array.

The way to get all records in the array matching your match is

foreach my $record (grep {/$match/i} @array) {
        print $record;
        $count++;
}
print $count;

Another way is quite more "beautiful":

my @records = grep {/$match/i} @array;
print $_ foreach (@records);
print scalar(@records); # equals to $count


By the way:
$match = 'HEllo'
           ^
Didn't you mean Hello. ?!
                 ^

Best Wishes,
Andrea

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to