in reply to Use of foreach

Your @file_names array doesn't contain what you think it does.

And furthermore, these aren’t the droids you’re looking for.

Try this:

use Data::Dumper 'Dumper'; die Dumper \@file_names;
I expect that you will see an undefined value in your array.

-guinex

Replies are listed 'Best First'.
Re^2: Use of foreach
by citromatik (Curate) on Jun 22, 2007 at 15:35 UTC

    And that undefined element should be (at least) the first in the array, because the OP only tries to print the first element (and then exits):

    foreach (@file_names){ print $_; exit; }

    citromatik

      I guess the exit; is there to track where something goes wrong at a particular line. I prefer to put die 'OK'; somewhere before/after suspected lines, whenever I'm in hard time debugging code. The program will be instantly death with calming message: OK at __FILE__ line __LINE__.

      Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re^2: Use of foreach
by thezip (Vicar) on Jun 22, 2007 at 17:16 UTC

    Hear, hear Win.

    Guinex is absolutely right about using Data::Dumper to view to contents of your trivial (and other not-so-trivial) arrays and hashes.

    This should have been the first thing you thought of when you saw the undefined array value warning. Please write this somewhere near your monitor so you'll have it handy next time it crops up.


    Where do you want *them* to go today?
A reply falls below the community's threshold of quality. You may see it by logging in.