Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: chop vs chomp

by philcrow (Priest)
on May 10, 2007 at 14:50 UTC ( [id://614648]=note: print w/replies, xml ) Need Help??


in reply to chop vs chomp

As Fletch alludes. There's a more important safety mechanism in chomp than silently skipping the action if there is nothing to chomp. It also allows operating system independence, since it eats the line ending for your OS. If you ask an applicant to write a script, they may choose chomp, merely because they don't know which operating systems you'll eventually ask them to deploy on.

Sorry, but porting to a new OS should not require chop hacking on code when a chomp in the first place would have handled the problem.

The Gantry Web Framework Book is now available.

Replies are listed 'Best First'.
Re^2: chop vs chomp
by Fletch (Bishop) on May 10, 2007 at 15:00 UTC

    It's more than just OS line ending issues: sometimes a logical record is more than one line. I've dealt with files in the past where the records consisted of several newline-terminated lines with a four character record separator along the lines of "EOR\n". chomp can handle removing this transparently (local $/ = "EOR\n"; while( <IN> ) { chomp; _handle_rec( $_ ) }), chop can't.

    And that's the important distinction: chomp deals with removing the current logical record ending, chop deals with removing a single trailing character.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: chop vs chomp
by Moron (Curate) on May 11, 2007 at 11:49 UTC
    No, "\n" gets chopped or chomped whatever the OS thinks "\n" is.
    __________________________________________________________________________________

    ^M Free your mind!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found