in reply to Re: Split web page, first 30 lines only -- :content_cb trick
in thread Split file, first 30 lines only
strict; use warnings; use Tie::File; use Fcntl; use LWP::UserAgent; use File::Slurp; my @lines; #Transfer URLS to a string variable; my $file = "G:/Research/SEC filings 10K and 10Q/Data/sizefiles1.txt"; #Now fill @pages array with contents of sizefile1.txt ... how? open (FH, "< $file") or die "Can't open $file for read: $!"; my @pages = <FH>; close FH or die "Cannot close $file: $!"; #connect variable used with GET?? my $ua = LWP::UserAgent-> new; #Initialize line counter; my $read_lines=1; #Primary loop through URLs ; foreach my $url (@pages) { my $response = $ua->get($url,':content_cb'=>\&head_only); print $response->content; } #Subroutine for primary loop; sub head_only { my ($data,$response,$protocol) = @_; my @lines = split "\n", $data; foreach my $line (@lines) { if ($read_lines ==31) { #reset line count' $read_lines = 1; print +("=" x 70), "\n"; #what is this? #die inside callback interrupt; die; } else { #print "line $read_lines: $line\n"; } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Split web page, first 30 lines only -- :content_cb trick
by Athanasius (Archbishop) on Mar 01, 2017 at 09:48 UTC | |
by wrkrbeee (Scribe) on Mar 01, 2017 at 14:41 UTC | |
Re^3: Split web page, first 30 lines only -- :content_cb trick and populate $response object
by Discipulus (Canon) on Mar 01, 2017 at 11:51 UTC | |
by wrkrbeee (Scribe) on Mar 01, 2017 at 14:43 UTC |