chomping and chopping lists
Saturday, 28 April 2007
Did you know that …
If you chop a list, each element is chopped. Only the value of the last chop is returned.
Taken from chop - perldoc.perl.org.
I just read the article Perplexing Parrot’s Parser - O’Reilly ONLamp Blog and while skimming the source I stumbled upon a call to the perl builtin subroutine chomp.
chomp(my @symbols = <$fh>);
First I thought the author was mistaken and wrote code to chomp the first one of his @symbols. A closer look at chomp’s perldoc page revealed that chomp indeed behaves that way. Passed lists are processed by chomping each element, whereas hashes are processed by chomping their values only. Same thing with chop.
A Short History of Nearly Everything
Seven Languages in Seven Weeks
I Am a Strange Loop
No. 1 — April 30th, 2007 at 09:30
The mistakes I make are usually dumber than using the wrong operator.