Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: TAB character as literal in editable prompt

by 1arryb (Acolyte)
on Dec 15, 2011 at 21:08 UTC ( [id://943832]=note: print w/replies, xml ) Need Help??


in reply to Re: TAB character as literal in editable prompt
in thread TAB character as literal in editable prompt

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://943832]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-16 05:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found