Click here to get back home

Remove a tab with backspace?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Remove a tab with backspace? valerie.seigneur 05-28-2008
Get Chitika Premium
Posted by valerie.seigneur on May 28, 2008, 11:05 am
Please log in for more thread options
Hi,

I'd like to use "\b" to delete a tab character, but it doesn't seem to
work. I've found several posts about the backspace character, but none
about this particular problem.

perl -e 'print "AB\bC\n";'
works fine and prints "AC", but
perl -e 'print "A\t\bC\n";'
prints "A-tab-C".

This is the simplified version, of course. In my script the extra tab
is there because I'm printing a tab each time I go through a loop, but
at the last iteration, I actually want a new line there, so I want to
get rid of the tab character and replace it with "\n".

Is this a problem with my perl code or with Apple's X11?

Val

Posted by Achim Peters on May 28, 2008, 11:38 am
Please log in for more thread options
valerie.seigneur@googlemail.com schrieb:
> I'd like to use "\b" to delete a tab character,

Whether it does or not depends on the terminal you print the tab and the
\b to. And other than possibly on the output device the tab is not
deleted anywhere, if at all.

> perl -e 'print "AB\bC\n";'
> works fine and prints "AC", but
> perl -e 'print "A\t\bC\n";'
> prints "A-tab-C".

Are you sure? I'd expect
"A-(n-1 spaces)-C"
where n is the number of spaces the tab was converted to.

> This is the simplified version, of course. In my script the extra tab
> is there because I'm printing a tab each time I go through a loop, but
> at the last iteration, I actually want a new line there, so I want to
> get rid of the tab character and replace it with "\n".

Wrong approach. Don't print the last tab in the first place.

BTW: You can see on your terminal, whether a line has a tab before the
\n or not? To me "abc\t\n" and "abc\n" look alike when printed: Nothing
to be seen in that line after the "abc" up until the right border of the
screen or window.

Bye
Achim



Posted by bugbear on May 28, 2008, 11:54 am
Please log in for more thread options
valerie.seigneur@googlemail.com wrote:
> Hi,
>
> I'd like to use "\b" to delete a tab character

Backspace is often an editing command to
terminals. No more, no less.

It does not (itself) perform editing.

Further, having a backspace in a string
can be VERY confusing if you output the string
to a terminal, since the preceding character
may be overwritten ON THE TERMINAL.

Howevere, the preceding character is still
in the string, which may well be two characters
longer (as shown by length()) than you
expect.

BugBear

Posted by valerie.seigneur on May 28, 2008, 1:15 pm
Please log in for more thread options
So how could I do what I describe above? I used to gather the output
of a whole line in a string and then use s/\t$/\n/ to change the last
tab to a newline,
but that sort of seems cumbersome. Are there any other ways to do it?
TIMTOWTDI? I still consider myself a beginner, so sometimes it's hard
to see the possible alternatives ;-)

Val.

Posted by Frank Seitz on May 28, 2008, 1:20 pm
Please log in for more thread options
valerie.seigneur@googlemail.com wrote:
> So how could I do what I describe above? I used to gather the output
> of a whole line in a string and then use s/\t$/\n/ to change the last
> tab to a newline,
> but that sort of seems cumbersome. Are there any other ways to do it?

perldoc -f chop

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Similar ThreadsPosted
all but one backspace April 27, 2005, 10:31 pm
remove sequence July 2, 2005, 10:27 am
[FR/EN] how to remove the characters '-' September 19, 2005, 12:15 am
Can't remove directory August 25, 2008, 2:58 pm
Best way to remove last word from a string August 3, 2004, 11:33 pm
How to remove a bunch of .log in windows August 11, 2004, 9:51 am
remove junk characters January 29, 2005, 2:59 am
How to remove double quotes March 21, 2005, 8:10 am
FAQ 9.4 How do I remove HTML from a string? March 23, 2005, 6:03 pm
remove a value from a callback array May 13, 2005, 5:18 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap