for($x=0; $x<3;$x++){
for($y=0; $y<3;$y++){
print $lines[$y][$x], " ";
}
}
####
map {
my $x=0;
map {
push @{$foo[$x]}, $_;
$x++;
} @$_;
} @lines;
####
#!/usr/bin/perl
use CGI::Pretty qw(:standard); # import CGI objects and functions
use CGI::Carp qw(fatalsToBrowser);
@a= (
["Food","Price","Check to order","1/2 off one item"],
["burger","\$2.00",checkbox ("One of these"),radio_group (-name=>"half off bonus", -value =>1)],
["chicken","\$2.50",checkbox ("and one of these, too"),radio_group (-name=>"half off bonus",-value =>2)],
["tofutii","\$1.75",checkbox ("and one of them, while we're at it."),radio_group (-name=>"half off bonus",-value =>3)],
);
@b= (
["Fruit" ,"Kiwi" , "Tangerine" , "Mango" , "Pomelo","Carambola"],
["Origin" ,"New Zealand" , "Florida" , "Venezuela" , "Mexico","Arizona"],
["Color" ,"Brown" , "Orange" , "Red & Green" , "Yellow"]
);
print header();
print start_html();
&make_table_from_AoA (1,0,1,0,@a);
print p,hr,p;
&make_table_from_AoA (1,1,1,4,@a);
print p,hr,p;
&make_table_from_AoA (0,0,0,2,@b);
print p,hr,p;
&make_table_from_AoA (1,1,1,1,@b);
####################
#
# make_table_from_Aoa
#
# parameters
# 1) $use_th : if this is true, the first line of the passed array will be used
# as an HTML header.
# 2) $transpose : swap axis of array
# 3) $check_array_size : if true, make sure each array has same # of elements
# 4) $border : size of border to put around table.
# 5) @l_array : holding tank for passed array.
#
####################
sub make_table_from_AoA {
local $use_th = shift;
local $transpose = shift;
local $check_array_size = shift;
local $border = shift;
local @l_array = @_;
#Make sure arrays are the same size. if not, die.
if ($check_array_size){
$size =scalar(@{$l_array[0]});
map {die "funky arrays : First array is $size, found one of ".scalar(@{$_}) if scalar(@{$_}) != $size}@l_array;
}
if ($transpose) {
local @tary;
map {my $x=0;
map {push @{$tary[$x]}, $_;$x++;} @$_;
} @l_array;
@l_array=@tary;
}
print table( {-border=>$border},
$use_th?th([@{shift @l_array}]):undef,
map{Tr(map{td($_)}@$_)}@l_array
);
}