Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: chomp() problems

by SparkeyG (Curate)
on Sep 24, 2002 at 17:31 UTC ( #200429=note: print w/ replies, xml ) Need Help??


in reply to chomp() problems

chomp will only remove the systems $/ ($INPUT_RECORD_SEPARATOR). In most Unix it is just \n, in DOS it's \r\n.
I guess you could fix the problem by:

{ local $/ = "\r\n"; chomp ($line); }
Edited to correct typo, and again edited to correct a typo and again edited to fix a type. A sick infant does wonders to your sleep habits, and therfore your typing skils ;) Note to self, do not post anything after cleaning up baby vomit. ;)


Comment on Re: chomp() problems
Download Code
Re^2: chomp() problems
by Aristotle (Chancellor) on Sep 24, 2002 at 17:43 UTC
    local $\ = '\r\n';
    You did of course mean to use double quotes there.

    Makeshifts last the longest.

Re: Re: chomp() problems
by fglock (Vicar) on Sep 24, 2002 at 17:56 UTC

    Oops. You mean $/ (INPUT_RECORD_SEPARATOR)
    instead of $\ (OUTPUT_RECORD_SEPARATOR)

    chomp works on $/

Re: Re: chomp() problems
by Wally Hartshorn (Friar) on Sep 24, 2002 at 18:36 UTC

    One correction:

    s/in DOS it's \n\r/in DOS it's \r\n/

    Sure, blame it on the baby! :-)

    Wally Hartshorn

Re: Re: chomp() problems
by bart (Canon) on Sep 25, 2002 at 00:51 UTC
    In most Unix it is just \n, in DOS it's \r\n.
    No that's not correct. On DOS and Win32, it's also "\n". You see, the trick is that when reading from a text file, "\015\012" (AKA CRLF, "\r\n") is converted into a bare "\012" (LF, "\n"). Therefore, chomp() doesn't have to remove "\r\n", because there commonly will be, should be, only a bare "\n". And as chomp and $/ only use fixed strings not regexes for their workings, you can't have it both ways at the same time.

    And that, boys and girls, is why it doesn't work here. Access does store line endings as CRLF pairs. And that isn't very Perl compatible. Therefore, when reading data from Access in a Perl script, you should always turn CRLF into "\n", and vice versa when storing data back into Access.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-08-31 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls