On 9/18/07, VUNETdotUS <[EMAIL PROTECTED]> wrote: snip > I liked Text::Table idea but it is not supported on my machine. > Now I try printf but I came across a few problems. The sample above > produces a good result. However, when I implement according to my > needs, I cannot printf my multidimensional array: > > #here is my multi array > my @results = (); > @data = ("12","123","1234"); > push(@results, @data); > @data = ("123","1234","12345"); > push(@results, @data); > > #here i print out > for my $row (@results) { > printf "%3.3s %5.5s %6.6s\n", @$row; > } > > #error: Use of uninitiated value in printf snip
That would be because @results is not a multidimensional array. When you say push @results, ("123", "1234", "12345"); you are saying to add those three scalars to the end of @results. To get a multidimensional array you must use an arrayref. If you are not going to reuse an array (ie it is declared in a very limited scope) you can say [EMAIL PROTECTED] to get a reference to the memory currently being used by @array, but if you want to just use a copy of the data currently in the array say [EMAIL PROTECTED] to create an anonymous array reference. Try this my @data; my @results; # "= ()" is pointless here @data = "12", "123", "1234"; push @results, [EMAIL PROTECTED]; @data = "123", "1234", "12345"; push @results, [EMAIL PROTECTED]; #here i print out for my $row (@results) { printf "%3.3s %5.5s %6.6s\n", @$row; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/