not sure how to title this post.
the code below gives the count i need, but i'm having trouble printing the count where i need it, which is in the third position. i've tried splice and other things, but i have to do that before the last statement, so i get a wrong count.
my $accounts_by_id = {};
for (@accounts) {
my($id, $rest) = split /,/, $_, 2;
$accounts_by_id->{$id}->{info} = $rest;
}
for (@purchases) {
my($id, $rest) = split /,/, $_, 2;
push @{$accounts_by_id->{$id}->{purchases}}, $rest;
}
for (@accounts) {
my($id, $rest) = split /,/, $_, 2;
{
my @five = splice
@{$accounts_by_id->{$id}->{purchases}}, 0, 5;
last unless @five;
#I NEED TO COUNT AND PRINT THE NUMBER OF ITEMS IN @FIVE HERE BUT I HAV
+EN'T INCREMENTED THE COUNTER YET
print "$id,$accounts_by_id->{$id}->{info},",
join(',', @five), "\n";
$count =0;
foreach $id(@five){
$count ++;
}
#THIS GIVES ME THE RIGHT COUNT
print "count is: $count endcount";
print "<br>";
redo if @five == 5;
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.