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

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!

Replies are listed 'Best First'.
Re^4: Need to count the number of entries in a array
by chromatic (Archbishop) on Jan 16, 2012 at 07:59 UTC

    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.

Re^4: Need to count the number of entries in a array
by Anonymous Monk on Jan 16, 2012 at 07:56 UTC

    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.