HamNRye has asked for the wisdom of the Perl Monks concerning the following question:

How do you print an array in a format?? I've looked around, but have not found it so far.

I would have thought this would work, but no...

@test = (A, B, C); format TEST= ~~ Test@< = @< $test $test .

I have looked back to my other code, and for some reason I was contencating my list with newlines and outputting in this fashion. I assume that was the work around I had used at the time, but is there a "real way" to do this??

~Hammy

Replies are listed 'Best First'.
Re: Printing an array in a format
by data64 (Chaplain) on Feb 23, 2002 at 21:59 UTC

    I am not sure what exactly you are trying to do there, but the code below works for me. This is all explained in perlfunc (look for format and write) and perlform.

    use strict; use warnings; use Diagnostics; my @test = qw( A B C ); write; format STDOUT = @<< ~ Test@< = @< @test .

    If you are not sure where to get the documentation, see How to RTFM


    <cite>Just a tongue-tied, twisted, earth-bound misfit. -- Pink Floyd</cite>

Re: Printing an array in a format
by grep (Monsignor) on Feb 23, 2002 at 21:36 UTC

    You should reread the perlform manpage again (you did read it before you posted didn't you :) ).

    Just glimpsing at your code you have no write. This would be a key problem, also you are wanting to print the array @test, but you are printing the scalar $test twice.



    grep
    grep> rm -f /bin/laden
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Printing an array in a format
by munchie (Monk) on Feb 23, 2002 at 21:47 UTC
    What exactly do you mean by format? Couldn't you just use a foreach loop to print out a formatted array?

    > munchie, the number munchin newb
    Llama: The other other white meat!
    (you had to be there :-P)