Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

count number of pages in two datafiles

by data67 (Monk)
on Aug 23, 2001 at 14:05 UTC ( [id://107327]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

I am Trying to find the best way to get a page count (number of pages in two datafiles). Basically I have to data files I want to compare. (Example: lets say one data file is 32 pages long and the next file is 30 pages long; now here I want to be able to add the number of pages in both files and retrieve the result). Any suggestions will be greatly appreciated.

Replies are listed 'Best First'.
Re: count number of pages in two datafiles
by clintp (Curate) on Aug 23, 2001 at 14:08 UTC
    One question: what's a page?
Re: count number of pages in two datafiles
by scain (Curate) on Aug 23, 2001 at 14:15 UTC
    Presumably, you have some definition of the number of lines that corresponds to a page. If you are on a unix box, you can get the number of line with wc:
    my @lines = `wc -l $data_file`; @lines[0] =~ /(\d+)\s/; my $linecount = $1;

    I know less about windows boxes, but you can still always open the file and read through it, adding up the number of lines as they go by:

    my $linecount=0; open FILE, $data_file; while (<FILE>) { $linecount++; } close FILE;
    Easy enough, though I suspect there may be a better way.

    Scott

    Updated wc to get only the number.

    update2: It's funny how it's always the simple questions: one thing that occurred to me is that this assumes there are no lines that will wrap on printing. If that is a good assumtion, fine. If not, code will have to be added to check the length of the line. If it is long enough to wrap, $linecount should be incremented by 2.

      oh, i am sorry a page has 56 lines
        Ok, then once you have $linecount (from whatever method), find the number of pages with
        my $linesperpage=56; my $pagecount; if ($linecount%$linesperpage == 0) { $pagecount = $linecount/$linesperpage; } else { $pagecount = int($linecount/$linesperpage) +1; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://107327]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.