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

ansitest.pl: print "If you can read this, CSI is not working.\n"; print "\033[2J" ; /* clear screen */ print "If this is the first line displayed, CSI is OK.\n";
running the above under activeperl 5.8 in a DOS window under W2K : the escape sequence is being ignored whereas an equivalent C program ansitest.exe works as expected. What's going on ?

Replies are listed 'Best First'.
Re: ANSI escape sequences
by liverpole (Monsignor) on May 25, 2006 at 11:25 UTC
    Hi pearle,

    Try using the module Win32::Console::ANSI, and read its documentation.   It should do what you want.

    For example:

    use strict; use warnings; use Win32::Console::ANSI; print "If you can read this, CSI is not working.\n"; print "\033[2J" ; # Clear screen print "If this is the first line displayed, CSI is OK.\n";

    By the way, you need to use '#' as a comment character in Perl ("/* ... */" and "//" are for C and C++).


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: ANSI escape sequences
by blazar (Canon) on May 25, 2006 at 11:27 UTC

    Try some *ANSI* module from CPAN, e.g. Term::ANSIColor. Personally that's the way I choose whenever I have to use ANSI sequences. If that's giving you the same problems, than you do not have a problem with perl, but with your terminal. In fact back in the days of good ole' DOS I used to have an ANSI driver enabled, but nowadays afaik Windows console is not ANSI enabled and I don't even know if there are "plugins" or whatever that will make it such.