
summer
Deleted
May 16, 2000, 1:33 PM
Post #2 of 2
(284 views)
|
|
Re: Detecting and printing certain number of lines
[In reply to]
|
Can't Post
|
|
my @href ; open IN, "somefile.html" or die $! ; while( <IN> ) { push @href, $1 if /(<a\s*href=[^>]+>[^<]+</a> )/io ; last if @href == 7 ; } close IN ; for ( 0..3 ) { print "$href[$_]\n" ; } =pod The above opens the file & reads line by line. For any line that has an href it copies the href as a string and puts it in the @href array; once we've got 8 strings it quits looking through the file and moves on to print the first 4. If you want sophisticated HTML parsing then look on CPAN for HTML::Parser. =cut
|