2

the \b "bakspace in perl doesn't works when we use it at the last of the string.

Eg: If we see the code, i have written

print "Hello\n";    
print "Hello\n";
print "\bHe\bllo\b";

It gives me this output:

Hello Hello Hllo

So should the highlighted oo be deleted or in case, the \n would have been deleted taking the control to the 2nd line?

kittykittybangbang
  • 2,380
  • 4
  • 16
  • 27
Viren
  • 29
  • 1
  • 3
    @T.J.Crowder answer at [link](http://stackoverflow.com/questions/6792812/the-backspace-escape-character-b-in-c-unexpected-behavior): "Your result will vary depending on what kind of terminal or console program you're on, but yes, on most \b is a nondestructive backspace. It moves the cursor backward, but doesn't erase what's there." – Rakholiya Jenish Jul 06 '15 at 18:12

1 Answers1

5

\b is a shorthand for \x08, so

print "a\b";

simply outputs bytes

61 08

Most terminals interpret 08 as a request to move the cursor one position to the left. If you want to "erase" a character, you need to overwrite it with another.

print "a\b \b";
ikegami
  • 367,544
  • 15
  • 269
  • 518