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.


In reply to Re: Print array from here-doc by johngg
in thread Print array from here-doc by sasrs99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.