stu meacham wrote: > After filling out a form, following a link, and getting the right content, I would like to print a range of lines from that content. Like so: > > my $mech = WWW::Mechanize->new(); > $mech -> get("http://www.website.com"); > > $mech->form_number( 1 ); > $mech->field(login => "username"); > $mech->field(password => "secret number"); > $mech->submit(); > $mech->success or die "post failed: ", $mech->response->status_line; > > $mech->follow_link( text_regex => qr/name of link/i ); > $mech->success or die "post failed: ", $mech->response->status_line; > > $mech->{content} or $mech->content() gives me the content from which > I would like to use the range operator (...) upon. I can't make any kind of > line operator work on the content object, though. > > my $file = $mech->{content}; > print "$file\n"; # this prints everything > > open FH, "$file"; #this no worky > while (<FH>) { > print if m/start_regex/...m/end_regex/; > } > > What would be the best way to print out a range of lines from the content > with 2 different delimiters? Do I have to make the content a file first and > then open a filehandle? Thanx, Stu
It should be just as easy as this (right?) my $content = $mech->content(); my @lines = splice(@{split(/\n/, $content)}, $start, $start + $range); content() should return a scalar that you can split on new lines and then just splice up. Michael Peters Venzia