Home : Products : DBMan : Discussions :

Products: DBMan: Discussions: problem on linear search (perl programming): Edit Log

Here is the list of edits for this post
problem on linear search (perl programming)
Hi all,

I've found some codes from 'Mastering Algorithms with Perl' O'Reilly.

Code:
sub linear_string
{
my ($array, $target) = @_;
for (my $i = @$array; $i--;)
{
print("$array->[$i]\n");
return $i if $array->[$i] eq $target;
}
return undef;
}

$path= 'd:\\atlog.txt';
open(LOGFILE, "< $path")
or die "Couldn't open $path for reading: $!\n";

$target = 'test';
while (<LOGFILE>)
{
@string= split(/\s+/, $_);
$index = linear_string( \@string, $target);
print("@string($index)");
print("$index\n");
}

It doesn't work! I mean it cannot search my 'target' string. Also it cannot print $index...

My 'atlog.txt' does contain the 'target' string.

Any idea?

Thanks
Cary

Last edited by:

caryhung: Apr 25, 2002, 7:49 PM

Edit Log: