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:
See splice, map. Also, please see Short, Self-Contained, Correct Example.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 }, ]
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.)
Also, I agree with dsheroh here that critical details of your application are missing and we are left guessing.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 }, ]
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |