Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Entering external data

by ido50 (Scribe)
on Aug 10, 2003 at 12:30 UTC ( [id://282604]=note: print w/replies, xml ) Need Help??


in reply to Entering external data

If you wanna delve more into the subject, read the material AcidHawk gave you. But just for the matter, to erase the linebreak use chop($data = <>); (You can also use chomp instead. chomp erases the last character only if it's a newline. chop erases the last character no matter what.

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

Replies are listed 'Best First'.
Re: Re: Entering external data
by Anonymous Monk on Aug 10, 2003 at 13:08 UTC
    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])
      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&#8208;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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found