Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

(Ovid) Re: How do you chomp your chomps?

by Ovid (Cardinal)
on Jan 09, 2001 at 03:02 UTC ( [id://50592]=note: print w/replies, xml ) Need Help??


in reply to How do you chomp your chomps?

Personally, I have never used the return value from chomp, but that's not to say it's useless. Did you know you can chomp an array?
my @array = ( "one\n", "two\n", "three", "four\n" ); my $result = chomp @array; print $result, $/; print @array;
In that snippet, $result is set to 3 and all elements of the array have had their trailing newline removed. Offhand, I don't see the utility of chomp returning the number of elements chomped, but I also remember that when I first started programming, I didn't see the utility of the ternary operator ( y = x ? y : x ). Now, I use it all the time.

chomp itself is very useful when I pull in data from a variety of sources and do something with them. I usually don't want a bunch of newlines unless I put them there.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found