Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Printing a String (TOO stupid?)

by RonW (Hermit)
on Jun 18, 2014 at 16:12 UTC ( #1090319=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Printing a String (TOO stupid?)
in thread Printing a String (TOO stupid?)

Updated

I was wrong. Somehow, I remembered it working differently.

But { local $/ = ''; chomp($x); } seems to work. Needs more testing and I'm not sure there would still be a performance benefit.


Try chomp; chomp; instead of chop; chop;

chomp is conditional. Being built in, I would expect it to be more efficient than a regex.


Comment on Re^3: Printing a String (TOO stupid?)
Select or Download Code
Re^4: Printing a String (TOO stupid?)
by Laurent_R (Parson) on Jun 18, 2014 at 18:46 UTC
    That's wrong in this specific case. Here, you have a Windows file with "\r\n" line ends. Under Unix, the chomp command will remove only the "\n" part, but not the "\r". Using chomp a second time will not remove the "\r" under Unix. So the printing goes back to line start and the three !!! overwrite the beginning of the line.

    The best solution here is to remove the "\r":

    chomp $line; $line =~ s/\r//g;
    or
    $line =~ s/[\r\n]//g;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-12-27 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls