Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: chomp() is confusing

by jesuashok (Curate)
on May 15, 2006 at 08:13 UTC ( #549393=note: print w/ replies, xml ) Need Help??


in reply to Re: chomp() is confusing
in thread Why chomp() is not considering carriage-return

hi aufflick

I am not sure whether you have tested this program in Windows or not


If you run your script on Windows, the carrage return and newline will both be removed (since it's expected that under Windows files will end in both a carriage return and a newline).

I tested this program in windows, which is not behaving in the way you have explained.

$one = "Hello\r\n"; print "Before chomp" , length($one) , "\n"; chomp($one); print "After Chomp" , length($one) , "\n";
output:-
Before chomp 7 After Chomp 6
From that I understood that only the newline is removed in chomp, not the carriage return.

"Keep pouring your ideas"


Comment on Re^2: chomp() is confusing
Select or Download Code
Re^3: chomp() is confusing
by aufflick (Deacon) on May 23, 2006 at 08:01 UTC
    Hmm, that doesn't sound right at all - is that perl under cygwin or with ActivState perl?
Re^3: chomp() is confusing
by ikegami (Pope) on May 23, 2006 at 16:52 UTC

    If you want to chomp \r\n, set $/ to \r\n:

    local $/ = "\r\n"; $one = "Hello\r\n"; print "Before chomp: " , length($one) , "\n"; chomp($one); print "After Chomp: " , length($one) , "\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-09-20 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls