Skip to content

How to clear terminal screen in Perl

homepage-banner

Introduction

When working with command-line scripts in Perl, it’s common to want to clear the terminal screen. This can be useful for improving the readability of your output and making sure users aren’t overwhelmed by too much text. In this blog post, we’ll explore a few different ways to clear the terminal screen in Perl.

Using ANSI Escape Sequences

print "\033[2J";    #clear the screen
print "\033[0;0H"; #jump to 0,0

use system

## for *nix
system("clear");
## for windows
system("cls");

Using a Module

use Term::ANSIScreen qw(cls);
cls();
Leave a message