RE: foreach loop



No, it doesn't. What is a "rlptxat" element? Where do they come from.

"rlptxat" is just an element indexed at 44 that has a value, in which I would like to sum up, when it has the same elements "cell" "sect" and "carr" in the record.

I hope this helps

Thank you,

Chris

At 8:03 PM -0600 3/20/11, Chris Stinemetz wrote:
Jim,

Thanks for your feedback. I am actually trying to sum up all rlptxat
elements that have the same cell, sect, and chan elements in the
array. I hope this clarifies.

No, it doesn't. What is a "rlptxat" element? Where do they come from.

You can define a multiple-level hash with three nested keys (cell,
sect, chan) to hold the sum of all elements with the same key values
(a triple):

my %sum;

Find values of cell, sect, and chan:

$cell = ?
$sect = ?
$chan = ?

Add the value with these keys to the sum:

$sum{$cell}{$sect}{$chan} += ?

Iterate over the result:

for my $cell ( sort keys %sum ) {
for my $sect ( sort keys %{$sum{$cell}} ) {
for my $chan ( sort keys %{$sum{$cell}{$sect}} ) {
print "Value of sum($cell,$sect,$chan) is
$sum{$cell}{$sect}{$chan}\n";
}
}
}

Good luck!

--
Jim Gibson
Jim@xxxxxxxxxx
.



Relevant Pages

  • RE: foreach loop
    ... I am actually trying to sum up all rlptxat elements that have the same cell, sect, and chan elements in the array. ...
    (perl.beginners)
  • RE: foreach loop
    ... I am actually trying to sum up all rlptxat elements that have the same cell, sect, and chan elements in the array. ... You can define a multiple-level hash with three nested keys to hold the sum of all elements with the same key values: ...
    (perl.beginners)
  • Re: foreach loop
    ... rlptxat at fixed column positions. ... cell, sect, and carr. ... I am actually trying to sum up all rlptxat ...
    (perl.beginners)
  • Re: Table Formula =SUM(ABOVE) give incorrect result when there is
    ... whenever there is only one row to sum in ANY part. ... to sum the columns above the merged cell. ... This template always work correctly for me except in cases when there is ... Below each Part there is a row for Sub Total Part-X, ...
    (microsoft.public.word.tables)
  • RE: combining LOOKUP and IF functions
    ... You need to use Match and get a cumulative sum of you percentages. ... cell I2 =A2+H2 ... It may be possible to use Lookup ... excel spreadsheet and then plot the result of the model. ...
    (microsoft.public.excel.worksheet.functions)