jpavus has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, This is part of my question previously, when I have a pl that separates the files into each CITY based (separating every set of textline). The problem now is, I cannot reset the PAGE NUMBERS on each filenames. It just continues e.g.: file 1: has pages 1,2,3,4 file 2: has pages 5,6,7,8,9 (this should reset to 1)
***** FILE 1 Orlando ***** FLORIDA Inventory Report CITY: Orlando Page1 111 Item1 $1000 222 Item2 $2000 449 Item3 $9999 ***** FILE 2 Miami ******** Should RESET the Page # to 1 ***** FLORIDA Inventory Report CITY: Miami Page2 349 Item1 $3050 FLORIDA Inventory Report CITY: Miami Page3 349 Item1 $3050 224 Item2 $2340 982 Item3 $9029
I tried the local and have sub to restore a static values but it never worked. Maybe there's simpler way to do it. ALSO: Do I just need to insert a SPECIAL CHAR in order to have PAGE breaks? Here's the code below:
my ($file); my $time = time; use POSIX 'strftime'; my $runtime = strftime '%Y/%m/%d %H:%M:%S', localtime; print $runtime; my $page_count = 0; while (<FILE>){ chomp($_); if ( /CITY/ ... /FLORIDA/ ) { my $county=0; if ( ($file) = $_ =~ m/CITY:\s+(\w+)/ ) { close(FH); dynamic(); if ($file != $var) { $page_count = 0; } $file .= '.txt'; open(FH, ">> CORAGN$file"); ++$page_count; print FH "RUN DATE/TIME: $runtime DE +PT OF INFO SYSTEM REPORT: COSRAGIN\ +n"; print " STATEWIDE D +AILY REPORT PAGE: $page_count\n"; } print FH "$_\n" unless $_ =~ m/FLORIDA/; } } close FILE; closedir DIR; sub visible { print "\nvar has value $var"; print "\nfile has value $file"; } sub dynamic { local $var = $file; visible(); }
Thanks in Advance..

Edit by castaway - linkified

Replies are listed 'Best First'.
Re: Issues on PAGE count and PageBreaks
by sh1tn (Priest) on Mar 14, 2005 at 23:42 UTC
    ... if ( /CITY/ ... /FLORIDA/ ){ $page_count++; ... }else{ $page_count = 0 } ...


      I've tried different way including that but all it does is just either increment by 1 until end-of-file or page_count is always 1.
        Problem solved. Thanks