[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [FWP] From "The Art of Perl", Ch. 1



Jeff Pinyan [mailto:jeffp@crusoe.net] says:

: Operating on Lists
: ------------------
: 
: array-to-hash
: 
: 	while (($k,$v) = each %{{ @list }}){ ... }

Dare I say it? This particular idiom causes an endless loop when I use it
(latest ActivePerl build (519): 5.005_03 built for MSWin32-x86-object). 

Looks like the 'each' iterator isn't incremented when you use %{{@list}}:

	#!perl -w
	use strict;

	$, = " => ";
	my @list = qw/one I two II three III/;

	print "\n\n----- CONTROL -----\n";
	my %list = @list; # One common array hashification idiom, free of
charge
	for(1..3){print each %list; print "\n"}

	print "\n\n----- EXPERIMENT 1-----\n";
	for(1..3){print each %{{@list}}; print "\n"}

	print "\n\n----- EXPERIMENT 2 -----\n";
	my $list = {@list};
	for(1..3){print each %{$list}; print "\n"}

	print "\n\n------ EXPERIMENT 3 -----\n\n";
	for(keys %{{@list}}){print "$_\n"  }
	for(values %{{@list}}){print "$_\n"  }

	__END__

Respectfully submitted,
Eli
________________________
Eli Evans
Text Preparation Manager
Libronix Corp.
mailto:eli@libronix.com
http://www.libronix.com
Ec 12:12; Jn 21:22



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe