Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Odd behaviour of chomp()

by shmem (Chancellor)
on Oct 27, 2015 at 08:28 UTC ( #1146075=note: print w/replies, xml ) Need Help??


in reply to Re: Odd behaviour of chomp()
in thread Odd behaviour of chomp()

Your post doesn't add anything new to this thread. Mine adds a correction to your last paragraph

The first case is what is used 99% of the time, because “the function is an English verb.” Effectively, it is an imperative statement. You want to “chomp” a string, and it does. If you use the implied-variable "$_" it also produces the documented result, even though nobody actually does that. If you use your own variable, it does not. Given that you probably don’t have the latest Perl installed on your machine and probably can’t change it, you have to code-around bugs like these. If the function is a verb, use it as a verb only.

which is wrong. "If you use your own variable, it does not." Of course it does! It is perfectly ok to use chomp on "your own variable." It would be interesting to find why assignment to $_ works, but fails with $line - but you don't even try, you just post the bizarre statement that this happens because “the function is an English verb.”

And then
If the function is a verb, use it as a verb only.

Wait, what?!? Where did you get that from? Where in the perl docs is stated, that "English Verbs" only behave correctly on "implied $_"? So we should never use a "own variable" with print,split, shift, unshift and so on?

See, sundialsvc4, these assertions which you just pull out from your pool of speculations, not knowledge, are what many monks here annoy and what they detest and condemn as misleading, specially to newbies, even if they make for a good laugh for experienced perlers.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2019-07-16 18:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?