Forums.ATC.no

Teknisk => Generelt teknisk => Emne startet av: ATC på 20. Oktober 2009, 13:22 pm

Tittel: Perl: Remove ANSI sequences from a string
Skrevet av: ATC20. Oktober 2009, 13:22 pm
When processing terminal data or text files containing ANSI escape sequences, it can sometimes be useful to filter these out
Tittel: [Solved] Perl: Remove ANSI sequences from a string
Skrevet av: ATC20. Oktober 2009, 13:22 pm
sub remove_ansi  {
  for (@_) {
    $_ =~ s/\033\[[\?|0-9|\;]+?[a-z]//gi;
  }
}

Use like 'chop' and 'chomp', for example:

remove_ansi $string; # Remove ANSI from $string
remove_ansi $a, $b; # Remove ANSI from $a and $b

Note:
$string = remove_ansi $string; # Does NOT do what you expect!