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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl -l 1

Status
Not open for further replies.

mrberry

MIS
Jun 15, 2004
80
0
0
US
I have just discovered the -l option to Perl. While it is great in saving me typing all those \n's, what if I do no want to put a line return to a print statement when I am using this?

I searched and can't seem to find a way to suppress the line return when using -l.

Is there a way of doing this?

Thanks in advance.
 
feherke, thanks for your reply.

I am aware of printf, but was hoping to be able to do this with having to change every print statement into a printf statment.

 
Never done that, but you should do [tt]$\=undef;[/tt] before the print statement that doesn't need the terminator. However the behavior of the [tt]-l[/tt] switch is then lost and you need to restore it by [tt]$\=$/;[/tt] (that's in fact what the switch does) or by [tt]$\="\n";[/tt]
If you like testing complex features (at least for me), you could use [tt]local $\=undef;[/tt] within the block containing the print statement in question, and the behavior of [tt]-l[/tt] should be automatically restored outside that block.

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
prex1, thanks! That is just what I was looking for!

I love Perl! Just like Unix, there is always a way to do what you want to do....and somebody who knows how to do it.
 
You don't need to explicitly reset it if you do:
Code:
local $\ = undef;
That will cause it to regain its default value once you get out of the block you're in.
 
seems easier to type \n than doing the reverse of letting perl add it automatically and then having to undef or reset $\ to not print the newline.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top