Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Entering external data

by Anonymous Monk
on Aug 10, 2003 at 13:08 UTC ( [id://282608]=note: print w/replies, xml ) Need Help??


in reply to Re: Entering external data
in thread Entering external data

chomp erases the last character only if it's a newline
Kind of but not really. 'perldoc -f chomp' says
This safer version of "chop" removes any trailing string that corresponds to the current value of $/ ...
Sure $/ is "\n" by default, but that's besides the point. Also, it's best to make a link to the documentation like chomp or chomp (perldoc:perlfunc:chomp|chomp] or [perldoc://chomp])

Replies are listed 'Best First'.
Re: Re: Re: Entering external data
by ido50 (Scribe) on Aug 10, 2003 at 13:19 UTC
    Well to be quite honest I got this sentence ("chomp erases the last...") from the Camel book. It's not a direct quote, that's just what I remembered. I would have looked it up again if I haven't returned the book to my university library last week.
    And about the documentation link, I'll do that from now on.

    -------------------------
    Live fat, die young

      Actually ido50 the description of chomp I get from perldoc -f chomp is as follows:

        chomp This safer version of "chop" removes any trailing string that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR in the "English" module). It returns the total number of characters removed from all its arguments. It’s often used to remove the newline from the end of an input record when you’re worried that the final record may be missin +g its newline. When in paragraph mode ("$/ = """), it removes all trailing newlines from the string. When in slurp mode ("$ +/ = undef") or fixed‐length record mode ($/ is a reference + to an integer or the like, see perlvar) chomp() won’t remove anythin +g thing. If VARIABLE is omitted, it chomps $_.

      Meaning that if you want to get rid of the newlines chomp is your better bet over chop.

      The command "perldoc" is your friend.


      Peter @ Berghold . Net

      Sieze the cow! Bite the day!

      Nobody expects the Perl inquisition!

      Test the code? We don't need to test no stinkin' code!
      All code posted here is as is where is unless otherwise stated.

      Brewer of Belgian style Ales

      Thus quoth the Camel-book on chomp:

      This function (normally) deletes a trailing newline from the end of a string contained in a variable. This is a slightly safer version of chop (described next) in that it has no effect upon a string that doesn't end in a newline. More specifically, it deletes the terminating string corresponding to the current value of $/, and not just any last character.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        "This function (normally) deletes a trailing newline from the end of a string contained in a variable. This is a slightly safer version of chop (described next) in that it has no effect upon a string that doesn't end in a newline."

        That's what I remembered.

        "More specifically, it deletes the terminating string corresponding to the current value of $/, and not just any last character."

        That's what I forgot (-: .

        -------------------------
        Live fat, die young

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-03-29 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found