Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

perlfunc:chop

by gods
on Aug 24, 1999 at 22:43 UTC ( #303=perlfunc: print w/replies, xml ) Need Help??

chop

See the current Perl documentation for chop.

Here is our local, out-dated (pre-5.6) version:


chop - remove the last character from a string



chop VARIABLE

chop LIST

chop



Chops off the last character of a string and returns the character chopped. It's used primarily to remove the newline from the end of an input record, but is much more efficient than s/\n// because it neither scans nor copies the string. If VARIABLE is omitted, chops $_. Example:

    while (<>) {
        chop;   # avoid \n on last field
        @array = split(/:/);
        #...
    }

You can actually chop anything that's an lvalue, including an assignment:

    chop($cwd = `pwd`);
    chop($answer = <STDIN>);

If you chop a list, each element is chopped. Only the value of the last chop() is returned.

Note that chop() returns the last character. To return all but the last character, use substr($string, 0, -1).


Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[ozboomer]: Howdy, all.. Trying this once more... Not really a perl question :(... but I don't know how to even title my query (more...)
[ozboomer]: There's a text file with lots of sections in it, like an '.ini/.conf' file. Each section can be 'used' or 'unused' by its application (more...)
[ozboomer]: Some folk want to use the text file as 'storage', keeping ALL items in it (a database); others call it an 'active document' that should only contain 'in-use' sections. Is there a 'good practice' for this sort of thing?

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-05-21 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?