chomping and chopping lists

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.

One Response to “chomping and chopping lists”

  1. chromatic writes:

    The mistakes I make are usually dumber than using the wrong operator. :)

Leave a Reply