Problem 1: I want all the numbers to line up when printed out.
The values could be 1, 2 or 3 digit numbers. My script is a CGI, so Im guessing I want to use printf qq(stuff here) but am not sure.

printf may not be useful to you here as (I think) you're outputting HTML, so whitespace will be ignored. Have you considered using a table?

Problem 2: with one of the keys I must iterate over the multiple values in the array separatley so I can set each of them as a hyperlink pointing to a different page.I emptied the multiple values into a new array (dereferencing ?) like this:
@values=@{$hash{$id}};
Then I used a foreach to go through the array. I was surprised to find loads of extra whitespace appearing. ie. I put into the values:1 2 3 4 5 6 etc. and out came:1(1 blank space)2(2 blank spaces)3(3 blank spaces).

That's almost certainly going to be a problem with the code you're using to display the data. Can't help much without seeing it.

Problem 3:I also have a problem (unless I turn strict off) when I try to print something for which there were no values pushed in. I was hoping in these situtations just the key would be printed.

Then only print the values if they are defined. Something like this:

foreach (keys %hash) { print "$_ : "; print "$hash{$_}" if defined $hash{$_}; }
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg


In reply to Re: hashes of arrays/printf by davorg
in thread hashes of arrays/printf by basm101

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.