On Aug 10, Tyler Longren said:

>my @scans;
>my $last_host = "192.168.1.1";
>while (<LOGFILE>) {
>      push (@scans, $_)
>      if m/$last_host/i;
>}

Your regex matches things like "19271683101".  Perhaps you want:

  push @scans, $_ if /\Q$last_host\E/;

The /i modifier is useless here, and the \Q...\E is to turn the . in your
variable into a \. because . is a regex metacharacter which means "match
anything".

>I try to show the number of elements in the array like so:
>print "$#scans";

$#scans is not the number of elements.  It's the last index used in the
array.  If you want the number of elements, you'll have to use @scans in
scalar context:

  print @scans . "\n";

or

  print @scans + 0, "\n";

My guess is your logfile isn't opened.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to