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

Output question

by oaklander (Acolyte)
on Dec 26, 2001 at 17:44 UTC ( #134389=perlquestion: print w/replies, xml ) Need Help??
oaklander has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that gives me the files and directory listing but I need it to print page by page because some of the outputs are very large. I could do the more command in unix but what would I use for a pc??
use File::Find qw(finddepth); die "GIVE DIRECTORY NAME AS AN ARGUMENT\n" unless @ARGV; *name = *File::Find::name; finddepth \&lis, @ARGV; if ( !-d ) { print "DIRECTORY NOT FOUND!\n"; exit(0); } else { sub lis { if (!-l && -d _) { $i++; print "$name is a DIRECTORY\n"; } else { $j++; print "$name\n"; } } $x=$i+$j; print "\nDIRECTORY COUNT = $i\n"; print "FILE COUNT = $j\n"; print "TOTAL RECORD COUNT = $x\n"; }
I tried putting a for loop for STDIN in this but it didnt work:
foreach($y=0) { print "$name is a DIRECTORY\n"; unless( $y++ % 80 ) { <STDIN>;
Please advise.

Replies are listed 'Best First'.
Re: Output question
by hotshot (Prior) on Dec 26, 2001 at 18:01 UTC
    I don't know if you have a simple solution here. I guess you'll have to implement a pager of your own (like more or less etc.), and that's not so simple, you'll need to read the list to an array or any other structure and output it to the screen according to the size and width of the window. Maybe someone here will have a better solution for you.

      I don't see why you should write your pager as '| more' will work both on unices and windoze...

      But, If you want to do it anyway, a simple test in front of each print :
      if(++$line > $LINEMAX) { $line=0; getc; }

      should be enough for simple/small scripts...
      Or to be a little bit cleaner, using print2 instead of print, whith print2 defined like this :
      sub print2 { if(++$line > $LINEMAX) { $line=0; getc; } print @_; }

      UPDATE :
      Term::ReadKey May be more appropriate than getc.
      Anyway you got the idea...
      UPDATE2 :
      This answer is for oaklander, I replied to the wrong post. Apologizes (especially to Hotshot).

      "Only Bad Coders Code Badly In Perl" (OBC2BIP)
        Don't assume that more is the right pager to use. It irritates those of us who joke that less is more. Here is a better way:
        use vars qw(%Config); use Config qw(%Config); print "My pager is $Config{pager}\n";

        Thanks for you quick response and answer to my question! It now works the way I wanted.

        Can you please explain what the 'getc'is??

        Also If I wanted to use the 'more' command, where would I put it in my script?? I tried several areas and it didnt work.

by chip (Curate) on Dec 27, 2001 at 02:16 UTC
    You might find IO::Page useful.

        -- Chip Salzenberg, Free-Floating Agent of Chaos

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://134389]
Approved by root
[shmem]: LanX: now I have to find a succinct transformation FOOL => MONK
[LanX]: yeah but Marto already proposed a new "Lex Sun-D" ...
[karlgoethebier]: the word really exists: http://www. urbandictionary. com/define.php? term=fool
[shmem]: ...possibly involving RTFM
[karlgoethebier]: big surprise!
[Eily]: LanX I try to avoid answering, but I did feel that this one post was going into much detail to prove a false claim (that SHA-1 is secure, I was just wrong about how insecure it is)
[LanX]: ironically...
[LanX]: yeah whatever ... I'm in the favorable condition to already autohiding him ... how can I judge the poor FOOLs who still see his contributions xD
[Eily]: he's been pretty saavy about threads that were implictly about him in the past. I think he might have deliberatly avoiding mentioning it for some reason (he got tired?)
[Eily]: he did mention one of his propositions: basically make it possible to ignore downvotes, by separating them more from the upvotes

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-07-24 17:21 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (356 votes). Check out past polls.