Ryan Dillinger wrote:
Hello All;
I was hoping to write this script in a more concise manner, also
eliminate the error I get with it, along with correcting it indexing at only one occurence. Thanks for your help!

#!/usr/bin/perl
use warnings;

print ($TargetString = <<TARGET);
The intellect of man is in...
........etc..
TARGET

$SearchString = "";
print "\nType the string \"in\" to begin a search: " . $SearchString;

$SearchString = <STDIN>;
chomp($SearchString);
print "\nSearch begun for \"" . $SearchString . "\"...";

my $IndexLocation = index($TargetString , $SearchString, 0);
print "\nString found at index " . $IndexLocation . "...";

$IndexLocation = ($IndexLocation + 1);
$IndexLocation = index($TargetString, $SearchString, $IndexLcation);
print "\nString found at index " . $IndexLocation . "...\n";

I forgot to mention: you've misspelled $IndexLocation in the second call to
index(). Your code gives a warning to this effect as it stands, but you seem not
to have noticed it? Using strict forces you to declare all the variables you use
and would have caught this without even trying to run the program.

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to