Forum Moderators: coopster & phranque

Message Too Old, No Replies

searching in perl

         

im_here

12:37 am on Sep 15, 2004 (gmt 0)

10+ Year Member



I want to write a program that will sort threw an array and tell me if a certin peace of data is in the array.

@vitem = ("1","2","3","4");
$citem = 0;

for my $vitem (@vitem)
{
if ($item == $vitem)
{
$citem++;
}
}

if ($citem == 0)
{ print "did not find";}
else {print "found";}

This seems to come up with found no matter what I put.

moltar

1:07 am on Sep 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[perl]
my @vitem = qw(1 2 3 4);
my $citem = 0;

foreach my $vitem (@vitem) {
$citem++ if $vitem = $item;
}

if ( $citem ) {
print 'Did not find.';
} else {
print 'Found.';
}
[/perl]