FAQ 8.7 How do I clear the screen?

Discussion in 'Perl Misc' started by PerlFAQ Server, Mar 6, 2011.

  1. This is an excerpt from the latest version perlfaq8.pod, which
    comes with the standard Perl distribution. These postings aim to
    reduce the number of repeated questions as well as allow the community
    to review and update the answers. The latest version of the complete
    perlfaq is at http://faq.perl.org .

    --------------------------------------------------------------------

    8.7: How do I clear the screen?

    (contributed by brian d foy)

    To clear the screen, you just have to print the special sequence that
    tells the terminal to clear the screen. Once you have that sequence,
    output it when you want to clear the screen.

    You can use the "Term::ANSIScreen" module to get the special sequence.
    Import the "cls" function (or the ":screen" tag):

    use Term::ANSIScreen qw(cls);
    my $clear_screen = cls();

    print $clear_screen;

    The "Term::Cap" module can also get the special sequence if you want to
    deal with the low-level details of terminal control. The "Tputs" method
    returns the string for the given capability:

    use Term::Cap;

    $terminal = Term::Cap->Tgetent( { OSPEED => 9600 } );
    $clear_string = $terminal->Tputs('cl');

    print $clear_screen;

    On Windows, you can use the "Win32::Console" module. After creating an
    object for the output filehandle you want to affect, call the "Cls"
    method:

    Win32::Console;

    $OUT = Win32::Console->new(STD_OUTPUT_HANDLE);
    my $clear_string = $OUT->Cls;

    print $clear_screen;

    If you have a command-line program that does the job, you can call it in
    backticks to capture whatever it outputs so you can use it later:

    $clear_string = `clear`;

    print $clear_string;



    --------------------------------------------------------------------

    The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
    are not necessarily experts in every domain where Perl might show up,
    so please include as much information as possible and relevant in any
    corrections. The perlfaq-workers also don't have access to every
    operating system or platform, so please include relevant details for
    corrections to examples that do not work on particular platforms.
    Working code is greatly appreciated.

    If you'd like to help maintain the perlfaq, see the details in
    perlfaq.pod.
     
    PerlFAQ Server, Mar 6, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad

    Clear all fields on a screen

    tshad, May 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,313
    tshad
    May 20, 2005
  2. owl
    Replies:
    2
    Views:
    903
  3. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,118
    Mark Fitzpatrick
    Jan 31, 2008
  4. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    1,068
    Steven Cheng[MSFT]
    Mar 6, 2007
  5. PerlFAQ Server

    FAQ 8.7 How do I clear the screen?

    PerlFAQ Server, Feb 11, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    128
    PerlFAQ Server
    Feb 11, 2011
Loading...

Share This Page