in reply to Re: Need to count the number of entries in a array
in thread Need to count the number of entries in a array

Beware of your map; chomp doesn't return the chomped string.


Improve your skills with Modern Perl: the free book.

  • Comment on Re^2: Need to count the number of entries in a array

Replies are listed 'Best First'.
Re^3: Need to count the number of entries in a array
by Marshall (Canon) on Jan 16, 2012 at 07:50 UTC
    Please tell me what a better formulation is?

    my ($title, $image, $counter...,@inventory) = map{chomp}<THEFILE>

    Ok, I made a simple mistake, and one that is common: map{chomp} should be map{chomp; $_} The return from map is the last statement, here $_ is chomped and that result, the chomped version of $_ should be the last statement.

    Thanks for pointing this out!

      Don't guess. Try it out, or read the documentation for chomp. I've made that mistake before with map and it's a head-scratcher the first two times.

      (It returns—depending on the line endings of the file—a bunch of copies of $/.)


      Improve your skills with Modern Perl: the free book.

      Most of "us", including the OP, don;t need telling.

      *You* could look it up.

      Or even try your fascile suggestions out, *before* advising the use of broken code as a replacement for perfectly fine, working code.

        Fascile:
        (esp. of a theory or argument) Appearing neat and comprehensive only by ignoring the true complexities of an issue; superficial.

        My simple error was easily corrected by three characters: ";$_" -that is superficial. My response was not superficial. To the contrary, I offered concrete advice directly related to the problem that did not ignore the complexities.