in reply to foreach problem

Enabling:

use warnings; use strict;

Should do it. This is very basic and you should be using it always.

Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill

Replies are listed 'Best First'.
Re^2: foreach problem
by GrandFather (Saint) on Mar 03, 2009 at 19:56 UTC

    Do what pray? The following code (without strictures)

    my @libs = qw{1 2 3 4}; foreach my $lib (@libs) { my $file = $lib{'file'}; print "reading $file\n"; }

    Prints:

    reading reading reading reading

    and with use strict added generates the error:

    Global symbol "%lib" requires explicit package name at ... line 7. Execution of ... aborted due to compilation errors.

    which is the 'requires explicit package name' that worried the OP (and quite rightly). The OP is using strictures and they have just saved his job/his marriage/his sanity/the world, or whatever. Good OP++!


    True laziness is hard work