[DFW.pm] Adding variables together based on commonality of different variable

Lisa Cloutier staurofilax77 at gmail.com
Tue Mar 25 09:51:47 PDT 2014


Matt, once I built the array of arrays, your solution worked brilliantly.
Thank you!


On Tue, Mar 25, 2014 at 11:22 AM, Matt Musgrove <MMusgrove at efji.com> wrote:

>  Lisa,
>
> If for whatever reason you aren't able to do this from within Oracle, try
> the following:
>
>                 #!/opt/perl/bin/perl
>
>                 use strict;
>
>                 use warnings;
>
>                 use Data::Dumper;
>
>
>
>                 my $markets = [
>
>                                 [ 'Market1', 65000, 3000 ],
>
>                                 [ 'Market1', 130000, 5000 ],
>
>                                 [ 'Market1', 65000, 4500 ],
>
>                                 [ 'Market2', 65000, 3000 ],
>
>                                 [ 'Market3', 32000, 800 ],
>
>                                 [ 'Market3', 32000, 1000 ],
>
>                 ];
>
>
>
>                 my %market;
>
>                 for my $market ( @{ $markets } )
>
>                 {
>
>                                 my ( $name, $high, $low ) = @{ $market };
>
>                                 $market{ $name }{high} += $high;
>
>                                 $market{ $name }{low} += $low;
>
>                 }
>
>
>
>                 print Dumper( \%market );
>
>
>
> *From:* Dfw-pm [mailto:dfw-pm-bounces+mmusgrove=efji.com at pm.org] *On
> Behalf Of *Lisa Cloutier
> *Sent:* Tuesday, March 25, 2014 11:18 AM
> *To:* dfw-pm at pm.org
> *Subject:* Re: [DFW.pm] Adding variables together based on commonality of
> different variable
>
>
>
> I'm playing with the output right now and I think I may have solved it,
> I'm still in process of writing it out.    Thanks for your reply!
>
> Lisa
>
>
>
> On Tue, Mar 25, 2014 at 11:16 AM, Sri Vedurumudi <sri at vedurumudi.com>
> wrote:
>
>
> Lisa,
>     Isn't it easier for you to alter the SQL query so it gives you the
> data summed up and pre-grouped?
>
> Regards,
> Sri
>
>     *Lisa Cloutier* <staurofilax77 at gmail.com>
>
> Tuesday, March 25, 2014 12:12 PM
>
> Hi All,
>
> This should be easy and I've done similar things before, but I can't seem
> to get the data structure to output properly.
>
> I have data in the following format:
>
> Market1 65000 3000
>
> Market1 130000  5000
>
> Market1 65000   4500
>
> Market2 65000  3000
>
> Market3 32000  800
>
> Market3 32000  1000
>
> What I need to do is get the markets so that they are unique so that I can
> use them as hash keys.  So I need to add all of the 2nd column and all of
> the 3rd column for each market so that there is only one entry per market,
> with the duplicate entries all added together.
>
> The data is coming out of an arrayref (from an Oracle database) so I don't
> have any code that shows the problem, just the foreach loop iterating
> through each reference in the arrayref.
>
> Any help would be greatly appreciated.
>
> Thanks,
>
> Lisa
>
> _______________________________________________
> Dfw-pm mailing list
> Dfw-pm at pm.org
> http://mail.pm.org/mailman/listinfo/dfw-pm
>
>
> _______________________________________________
> Dfw-pm mailing list
> Dfw-pm at pm.org
> http://mail.pm.org/mailman/listinfo/dfw-pm
>
>
>   This e-mail transmission, and any documents, files or previous e-mail
> messages attached to it, may contain confidential information. If you are
> not the intended recipient, or a person responsible for delivering it to
> the intended recipient, you are hereby notified that any disclosure,
> distribution, review, copy or use of any of the information contained in or
> attached to this message is STRICTLY PROHIBITED. If you have received this
> transmission in error, please immediately notify us by reply e-mail, and
> destroy the original transmission and its attachments without reading them
> or saving them to disk. Thank you.
>
> _______________________________________________
> Dfw-pm mailing list
> Dfw-pm at pm.org
> http://mail.pm.org/mailman/listinfo/dfw-pm
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/dfw-pm/attachments/20140325/e94d6ad2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 770 bytes
Desc: not available
URL: <http://mail.pm.org/pipermail/dfw-pm/attachments/20140325/e94d6ad2/attachment.jpg>


More information about the Dfw-pm mailing list