Perl forgets variable every other pass in loop???



Greetings!

Kindly consider this code which illustrates my question:

#!/usr/bin/perl
use strict;

my $column_ref = [
{ 'description' => { 'align' => 'left' } },
{ 'total' => { 'align' => 'right' } },
];
for (1..6) {
foreach my $format_ref( @{$column_ref} ) {
my( $column, $attr_ref ) = each %{ $format_ref };
print "'$column', '$attr_ref'\t";
}
print "\n";
}
__END__

What I would EXPECT to see from this program is something like this:

'description', 'HASH(0x8206710)' 'total', 'HASH(0x81fd314)'
'description', 'HASH(0x8206710)' 'total', 'HASH(0x81fd314)'
'description', 'HASH(0x8206710)' 'total', 'HASH(0x81fd314)'
'description', 'HASH(0x8206710)' 'total', 'HASH(0x81fd314)'
'description', 'HASH(0x8206710)' 'total', 'HASH(0x81fd314)'
'description', 'HASH(0x816dc28)' 'total', 'HASH(0x8192258)'

But, for some strange reason, Perl seems to "forget" the value of $column_ref on every OTHER pass. What I ACTUALLY see is this:

'description', 'HASH(0x816dc28)' 'total', 'HASH(0x8192258)'
'', '' '', ''
'description', 'HASH(0x816dc28)' 'total', 'HASH(0x8192258)'
'', '' '', ''
'description', 'HASH(0x816dc28)' 'total', 'HASH(0x8192258)'
'', '' '', ''

Can anyone tell me what is happening to $column_ref???

Thanks!

--
David Filmer (http://DavidFilmer.com)
The best way to get a good answer is to ask a good question.
.



Relevant Pages

  • Re: When to "use strict" when teaching?
    ... >>being influenced by the history of Perl ... history bias you" essentially the same as saying you are not ... An understanding of how symbolic references work is neither necessary ... I say don't expose people to the idea of omitting "use strict" until ...
    (comp.lang.perl.misc)
  • RE: I need help here
    ... Here's the Big Secret about Perl variables that most people learn ... use strict; ... : $outputfile = shift; ... You will often see a usage message in a script which deals ...
    (perl.beginners)
  • Re: Perl Peeves
    ... the context is known at compile time. ... use strict; ... well-defined in Perl. ... number/string ambivalence of scalars. ...
    (comp.lang.perl.misc)
  • Re: newbie with a question on syntax
    ... pairs of items to the programmer (Perl doesn't care). ... The = operator** is called the assignment operator. ... if you are not using the strict pragma. ...
    (perl.beginners)
  • RE: simple references question
    ... Perl will not. ... Subject: simple references question ... If you want to alter the contents of the original array, ... Always use strict and warnings. ...
    (perl.beginners)