Perl forgets variable every other pass in loop???
- From: David Filmer <usenet@xxxxxxxxxxxxxxx>
- Date: Wed, 27 Aug 2008 16:23:39 -0700
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.
.
- Follow-Ups:
- Re: Perl forgets variable every other pass in loop???
- From: attn.steven.kuo@xxxxxxxxx
- Re: Perl forgets variable every other pass in loop???
- Prev by Date: Re: perl multithreading performance
- Next by Date: Re: Perl forgets variable every other pass in loop???
- Previous by thread: Truncate an array when you have a ref to it?
- Next by thread: Re: Perl forgets variable every other pass in loop???
- Index(es):
Relevant Pages
|