in reply to using format to align

Play around with this, then read the docs again.
use strict; use warnings; my @row; my @stuff = ( [qw(foo bar 3)], [qw(foo2 bar2 4)], [qw(foo3 bar3 5)], ); for (@stuff) { @row = @$_; write; } format STDOUT_TOP = ---------------------------------- NAME LAST COUNT ---------------------------------- . format STDOUT = @<<<<< @||||| @### @row .
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: using format to align
by Anonymous Monk on Mar 27, 2003 at 15:41 UTC
    Just one more questions,
    Is it possible to dump the entire contents of an array in a cloumn instead of iterating through each one?
      I am not sure i follow you ... do you mean the contents of the 'container' @stuff or @row? Or do you mean you want to print out columns instead of rows? I chose @row because i am lazy ;). I could have written it like so (only pertinent code shown - untested):
      my ($foo,$bar,$baz); for my $row (@stuff) { ($foo,$bar,$baz) = @$row; write; } format STDOUT = @<<<<< @||||| @### $foo,$bar,$baz
      So, if i am reading your question correctly, the answer is no. You have to iterate through each row. Now, if you are wanting to use a 'landscape' style output instead of a 'portrait' style output, you will need to do a lot more work. Formats won't transpose 2-D arrays for you, but Math::Matrix will:
      use Data::Dumper; use Math::Matrix; my $a = Math::Matrix->new( [1,0,0], [1,0,0], [1,0,0], ); print Dumper $a->transpose();
      Hope this helps ...

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      
Re: (jeffa) Re: using format to align
by Anonymous Monk on Mar 27, 2003 at 15:24 UTC
    Thanks,
    That was very helpful :)