in reply to TAB character as literal in editable prompt

Not that hard, probably:

$_ = "alpha\tbravo\tcharlie\n"; print; s/\t/\\t/g; print; ### You'd have user edit it s/\\t/\t/g; print; ### Write back to file

Replies are listed 'Best First'.
Re^2: TAB character as literal in editable prompt
by 1arryb (Acolyte) on Dec 15, 2011 at 21:08 UTC

    Hi TJPride,

    It works. Using Term::ReadLine, the first regular expression is unnecessary. This package appears to escape '\' characters as they are input without disturbing the rest of the string. I know this because the first version (which pre-escaped the TABs) also worked.

    I now have:

    #!/usr/bin/perl use File::Basename; use Term::ReadLine; my $inFile = $ARGV[0]; die "no inFile" unless $ARGV[0]; open (my $in, "<", $inFile) or die "Can't open $inFile for reading."; my $term = new Term::ReadLine(basename($0)); while(my $before = <$in>) { chomp($before); my $after = $before; # Not needed, unless you want to see the escapes. # $after =~ s/\t/\\t/g; for (;;) { print "BEFORE: $before\n"; $after = $term->readline("AFTER: ", $after); my $ans = $term->readline("Accept? (y/n) -> ", "y"); if ( $ans =~ /^[Yy]/ ) { $after =~ s/\\t/\t/g; print "AFTER: $after\n\n"; last; } } }

    Thanks!

    Larry