in reply to grabbing N lines after matching one?

couldn't seem to edit my last comment....

here is what I have so far (first version to make it past -w):

use strict; use LWP::Simple; use Date::Business; my $content = get("http://quotes.barchart.com/quote.asp?sym=qsft&code= +BGND"); open( FILE, ">stocks.txt" ) or die; print FILE $content; close FILE; my $today = new Date::Business(); my $date = $today->image(); my ($century, $year, $month, $day) = unpack "A2 A2 A2 A2", $date; my $search_date = sprintf "%s/%s/%s", $month, $day, $year; ###testing on a weekend :) $search_date = "09/15/00"; open( STOCK, "stocks.txt" ) or die; my (@lines, $matcher); while ( <STOCK> ) { if ( m/$search_date/ ) { push @lines; if ( $matcher eq "" ) { $matcher = "1"; } else { $matcher++; } } if ( $matcher eq "6" ) { last; } } close STOCK; print "@lines\n\n";

-- I'm a solipsist, and so is everyone else. (think about it)

Replies are listed 'Best First'.
RE: RE: grabbing N lines after matching one?
by mdillon (Priest) on Sep 16, 2000 at 21:02 UTC
    the main problem i see with this code is the following: push @lines; this line does nothing, so the @lines array is always empty whe you attempt to print its contents. what you probably wanted is: push @lines, $_; also, you are testing the equality of a numeric variable against an integer with eq which is the string equality operator, as opposed to == the numeric one.

      bingo :) ...and just the other day my pal was chiding me for not using the default actions enough. I guess I too overzelous with them this time, I thought 'push' would just shove $_ in there lacking any other arguement. RTFM on me :)

      -- I'm a solipsist, and so is everyone else. (think about it)