Hi, Bill,
For fast array operations, I like to use map.
Ex:
$testnum = 1;
map { $bool = 'true' if $_ == $testnum } @your_array;
Regards,
John
--
John T Shea
[EMAIL PROTECTED]
Bill - compuserve <[EMAIL PROTECTED]> wrote:
> Hi List
>
> I have an array and all I need to do is to find ou
Bill - compuserve <[EMAIL PROTECTED]> wrote:
: Hi List
:
: I have an array and all I need to do is to find out if a
: number is present in the array or not.
:
: Currently I just do a 'foreach' on the array and and check the
: number against the array element. I was wondering if there is
: any fu
Thanks David
yes - that'd work for me here. I'll do a little rewrite :-)
Bill
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Sent: 19 January 2005 23:45
To: Bill - compuserve; activeperl mailing list
Subject: RE: finding if a number is in an array
Try this:
#!usr/bin/perl
use strict;
use warnings;
my $array = [0,1,2,4,8,16];
my $num1 = 8;
my $num2 = 32;
is_present($num1);
is_present($num2);
sub is_present
{
my $number = shift;
if (grep $_==$number,@$array)
{
print "number
",$number," is present!\n";
}
else
[EMAIL PROTECTED] wrote:
> Hi List
>
> I have an array and all I need to do is to find out if a number is
> present in the array or not.
Don't put in an array, use a hash then it becomes just one statement to
make it happen verses iteration over the array.
Use the numbers as the