Skip to content

Instantly share code, notes, and snippets.

@ab5tract
Last active August 29, 2015 14:14
Show Gist options
  • Save ab5tract/4961802803d3e5fb489d to your computer and use it in GitHub Desktop.
Save ab5tract/4961802803d3e5fb489d to your computer and use it in GitHub Desktop.
mishandling-regexes-or-escapes
processed escape sequence as 13 elems
\x[1b][24;36H
manual escape sequence is 8 elems
my ($x,$y) = 13,13;
my $raw = qq:x{ tput cup $y $x };
my @parts = ($raw.perl.subst('"','', :g) ~~ rx{ (.+) (\d\d) (.+) (\d\d) (.+) }).values;
@parts[1,3] = 24,36;
my $broken = @parts.join('');
say "processed escape sequence as {$broken.comb.elems} elems";
say $broken; # or say @parts.join is the same
# prints: "\x[1b][24;36H";
my $manual = "\x[1b][24;36H";
# say $manual; # uncomment to move cursor
say "manual escape sequence is {$manual.comb.elems} elems";
@FROGGS
Copy link

FROGGS commented Jan 26, 2015

my ($x,$y) = 13,13;
my $raw    = qq:x{ tput cup $y $x };

$raw ~~ s:1st[\d+] = "24";
$raw ~~ s:2nd[\d+] = "36";

say $raw.perl; # just to check

say $raw # should have an effect

@ab5tract
Copy link
Author

Thanks FROGGS! This also explains how to 'search/replace' on a string in a much less intrusive way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment