if $#scans==-1, then the array is empty (of course!)
Are you checking to make sure LOGFILE opened correctly?
-----Original Message-----
From: Tyler Longren [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 10, 2001 9:19 AM
To: Perl-Beginners
Subject: number of elements in array is -1?
Hello everyone,
I have a problem. I just want to print the number of elements in an
array. Here's the code:
my @scans;
my $last_host = "192.168.1.1";
while (<LOGFILE>) {
push (@scans, $_)
if m/$last_host/i;
}
shouldn't that put all of the results into the @scans array? I know
there'd just be a bunch of the same value.
$array[0] would equal 192.168.1.1
and $array[1] would equal 192.168.1.1
I try to show the number of elements in the array like so:
print "$#scans";
But that prints "-1". I know for a fact there are at least 2 entries in
LOGFILE that have an IP of 192.168.1.1.
Thanks,
Tyler Longren
Captain Jack Communications
[EMAIL PROTECTED]
www.captainjack.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]