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]
Re: number of elements in array is -1?
Jeff 'japhy/Marillion' Pinyan Fri, 10 Aug 2001 07:04:18 -0700
- number of elements in array is -1? Tyler Longren
- RE: number of elements in array is -1? Jeff 'japhy/Marillion' Pinyan
- RE: number of elements in array is -1? Mooney Christophe-CMOONEY1
- Re: number of elements in array is ... Tyler Longren
- Re: number of elements in array is -1? Brett W. McCoy
- Re: number of elements in array is -1? Tyler Longren
- Re: number of elements in array is ... Jeff 'japhy/Marillion' Pinyan
- Re: number of elements in array is ... Brett W. McCoy
- RE: number of elements in array is -1? Bob Showalter
- RE: number of elements in array is -1? Mooney Christophe-CMOONEY1
- Re: number of elements in array is ... Tyler Longren