Gossamer Forum
Home : Products : DBMan : Discussions :

problem on linear search (perl programming)

Quote Reply
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
Quote Reply
Re: [caryhung] problem on linear search (perl programming) In reply to
I think as this is not directly related to DBMan you may want to post your question in the perl programmer forum.

There you will find many more who are into programming and willing to help you with your code.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] problem on linear search (perl programming) In reply to
Hi LoisC,

In fact, I'm programming a 'timer' for my DBMan which is my previous problem (I've posted it in this forum). Now I try to use 'AT' command in order to work as a 'timer'.

Anyway, I would like to know where is the Perl Forum, please let me know.

Thanks
Cary
Quote Reply
Re: [caryhung] problem on linear search (perl programming) In reply to
If you click on Home or main Index the perl programming forum is within the section "General"

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] problem on linear search (perl programming) In reply to
Hi LoisC,

Thanks!
Cary