in reply to Print array from here-doc

I'm guessing from your post here and from what look like column headings in your here-doc that you have an array of arrays that you want to make a table from. The following code does that by using sprintf to format each sub-array. The code seems to have a glitch where the second and subsequent lines have the first column pushed one space to the right. I can't see what's causing that at present so I'll show the code as it stands to illustrate the principle.

use strict; use warnings; my @SKUs = ( [ q{Bumble}, q{Broth}, 16 ], [ q{Wedgie}, q{Benns}, 22 ], [ q{Party}, q{Games}, 6 ], ); local $"; my $msg = <<END_OF_BODY; The number of SKUs that have been flagged as DeleteMe Here is the list of SKUs and their counts: PLANNERCODE\tDEALER\tCOUNT ----------------------------- @{ [ map { sprintf qq{%11s\t%6s\t%5d\n}, @$_ } @SKUs ] } END_OF_BODY print $msg;

Here's the (slightly flawed) output. If any Monk can see what is causing the misalignment I'd be very interested in finding out.

The number of SKUs that have been flagged as DeleteMe Here is the list of SKUs and their counts: PLANNERCODE DEALER COUNT ----------------------------- Bumble Broth 16 Wedgie Benns 22 Party Games 6

I hope I have guessed right and this of use to you.

Cheers,

JohnGG

Update: shigetsu spotted my error, thanks. local $"; line inserted above here-doc to suppress the normal list separator of a space that was throwing things off.

Replies are listed 'Best First'.
Re^2: Print array from here-doc
by shigetsu (Hermit) on Apr 25, 2007 at 22:48 UTC
    If you replace
    my $msg = <<END_OF_BODY;
    with
    local $"; my $msg = <<END_OF_BODY;
    it should work as expected.
      Ahhh, of course! Why didn't I think of that?

      Thank you,

      JohnGG

        BINGO!!! Thank you very much.