It looks as if you might be starting with an array of hashes (an AoH) and you want to add some elements (additional hashes) after the first element of the existing array. If so, one way:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @ra = ( { 'day' => 1, 'Balance' => '183.57', 'payment' => 0, 'Total' => 0, +}, { 'day' => 4, 'Balance' => '12.86', 'payment' => 0, 'Total' => 0, +}, ); dd \@ra; ;; my @add_after_first = map { { 'day' => $_, qw(Balance - payment - Total -) } } 2, 3; ;; splice @ra, 1, 0, @add_after_first; dd \@ra; " [ { Balance => "183.57", Total => 0, day => 1, payment => 0 }, { Balance => "12.86", Total => 0, day => 4, payment => 0 }, ] [ { Balance => "183.57", Total => 0, day => 1, payment => 0 }, { Balance => "-", Total => "-", day => 2, payment => "-" }, { Balance => "-", Total => "-", day => 3, payment => "-" }, { Balance => "12.86", Total => 0, day => 4, payment => 0 }, ]
See splice, map. Also, please see Short, Self-Contained, Correct Example.

Update: A variation. Factoring out the null items list into the  NULL_ITEMS constant may be useful in other situations in your code. (Update: Oops... I just noticed that the "null" value I'm using in this example is, for some reason, a  ' (single-quote) instead of a  - (hyphen). Oh, well. I think you can get the idea, so I'm not going to change the code.)

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "use constant NULL_ITEMS => map { $_ => '\'' } qw(Balance Total day pa +yment); ;; my @ra = ( { 'day' => 1, 'Balance' => '183.57', 'payment' => 0, 'Total' => 0, +}, { 'day' => 4, 'Balance' => '12.86', 'payment' => 0, 'Total' => 0, +}, ); dd \@ra; ;; splice @ra, 1, 0, map { { NULL_ITEMS, 'day' => $_ } } 2, 3; dd \@ra; " [ { Balance => "183.57", Total => 0, day => 1, payment => 0 }, { Balance => "12.86", Total => 0, day => 4, payment => 0 }, ] [ { Balance => "183.57", Total => 0, day => 1, payment => 0 }, { Balance => "'", Total => "'", day => 2, payment => "'" }, { Balance => "'", Total => "'", day => 3, payment => "'" }, { Balance => "12.86", Total => 0, day => 4, payment => 0 }, ]
Also, I agree with dsheroh here that critical details of your application are missing and we are left guessing.


Give a man a fish:  <%-{-{-{-<


In reply to Re: How to set hash values to '-' . (updated) by AnomalousMonk
in thread How to set hash values to '-' . by Sami_R

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.