Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing back slash in perl 1

Status
Not open for further replies.

rameshbhats

Technical User
Dec 7, 2010
8
GB
Hi,

I am writing a perl script where in I need to print "backslash(\)" in the terminal. This is not being possible for me as \ is considered as escape character.
Following the output requirement
Hi This is ramesh \
typing this question \

But if I write following code
print "Hi This is ramesh \\n"
print "typing this question \\n"

I get
Hi This is ramesh \n
typing this question \n

The requirement is such that there should not be any space between \ & end of line.

Please guide me on this.

Thanks in advance
Ramesh
 
Hi

Escape it with backslash ( \ ) :
Code:
[b]print[/b] [green][i]"Hi This is ramesh [highlight][i]\[/i][/highlight]\\n"[/i][/green][teal];[/teal]
[b]print[/b] [green][i]"typing this question [highlight][i]\[/i][/highlight]\\n"[/i][/green][teal];[/teal]

Feherke.
 
Indeed. What was happening with your original attempt was that the first backslash was escaping the \n causing it to be treated as a literal.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top