Gary Nielson wrote:
> 
> I am trying to write a script that will open a file of headlines by
> section. The first field (separated by the "|" delimiter) is the section
> name. The script will go sequentially down the file. There may be up to 25
> headlines per section, all listed together before the next
> section comes up. However, some people want only, say, 5 headlines
> per section, others 10. Therefore, I want to have a counter that will keep
> track of the number of lines the script has run through by section,
> compare it with the maximum number needed, and only deliver that number,
> then go on to the next section and do the same.
>

How about using a hash? 

Code not tested, but you'll get the idea. 

 my (%all_section, $max_articles);
 $max_articles = 5;
 
> open(SITE, ">$site_location/$filename") ||
> die "cannot open
> $site: $!"; open(FH, "$outputfile") || die "cannot read $outputfile: $!";
> @fields = <FH>;
> foreach $field (@fields)
> {
>         $count = 0;
>         ($section,$url,$headline,$summary)=split('\|',$field);
>         $url =~ s/$siteurl//gi;

          $all_section{$section}++;
          print SITE "<li><a href=\"$url\">$headline</a>\n" if
$all_section{$section} <= $max_articles);
           
>       #  while  (/$section/) {
>       #  # the same or less than the number of headlines variable below
>       #  if (++$count =< $headline_number) {
>       #  print SITE "<li><a href=\"$url\">$headline</a>\n";
>       #          }
>       #  }
> close SITE;
> close FH;
>         }
> 
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to