Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Output question

by hotshot (Prior)
on Dec 26, 2001 at 18:01 UTC ( [id://134391]=note: print w/replies, xml ) Need Help??

in reply to Output question

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.


Replies are listed 'Best First'.
Re: Re: Output question
by arhuman (Vicar) on Dec 26, 2001 at 18:14 UTC
    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.

        You're welcome...

        For the getc you better read the doc (or follow the link) as it will be more accurate and clear than I could ever be.
        (anyway perldoc and/or SuperSearch and/or the camel book, must now be a a reflex for you Perl lover ;-)

        Now for the use of the more command, just forget about using 'more' IN your script, use it the unix way
        (joining several simple but efficient commands to do a complex task...) via pipe.
        Only display the lines on the screen in your script and then using 'more' for the paging part :

        perl | more

        "Only Bad Coders Code Badly In Perl" (OBC2BIP)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://134391]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-06-15 14:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.