Routine as argument -- generic variables not working
===

I am working on writing a gaming system (wargames, etc.) and am creating the system for creating and displaying hex maps.  I realized quickly that I am repeatedly doing a nested loop of x=(0..maxx) and y=(0..maxy).  So I attempted to adapt some code I found somewhere (one of the advanced perl books, I forget where) to create an easier way to do this sort of looping thing.  This is what I came up with:

    sub fillmap (&@) {
    	my $code = shift;
    	no strict 'refs';
	use vars qw($x $y);
	my $caller = caller;
    	local(*{$caller."::x"}) = \my $x;
    	local(*{$caller."::y"}) = \my $y;
    	foreach $x (0..5) {
    		foreach $y (0..3) {
    			warn "fillmap $x,$y\n";
    			&{$code}();
    		}
    	}
    }

Note: the warn statement is for debugging.  I also simplified the x and y ranges (the array passed in determines the maxx and maxy values, but I didn't want to muddy this discussion with the routines for calculating them... I just hard-coded them to maxx=5 and maxy=3)

So, this execution of this routine like so:

    fillmap {warn "$x,$y\n";} @map;

should yield a list of the x,y pairs.  But instead, it gives me this:

    fillmap 0,0
    ,
    fillmap 0,1
    ,
    fillmap 0,2
    ,
    fillmap 0,3
    ,
    fillmap 1,0
    ,
    fillmap 1,1
    ,
    fillmap 1,2
    ,
    fillmap 1,3
    ,
    fillmap 2,0
    ,
    fillmap 2,1
    ,
    fillmap 2,2
    ,
    fillmap 2,3
    ,
    fillmap 3,0
    ,
    fillmap 3,1
    ,
    fillmap 3,2
    ,
    fillmap 3,3
    ,
    fillmap 4,0
    ,
    fillmap 4,1
    ,
    fillmap 4,2
    ,
    fillmap 4,3
    ,
    fillmap 5,0
    ,
    fillmap 5,1
    ,
    fillmap 5,2
    ,
    fillmap 5,3
    ,

Note, the "fillmap" lines are from the subroutine for debugging.  But instead of each x,y pair, I just get the comma ($x and $y are empty, or perhaps undefined).

What am I doing wrong?
