Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Create a Hash Dynamically and add the values of same key

by hbm (Hermit)
on Jun 18, 2013 at 14:08 UTC ( #1039567=note: print w/replies, xml ) Need Help??


in reply to Create a Hash Dynamically and add the values of same key

Suggestions for your MAP loop - rather than:

while ( <MYFILE> ) { chomp; (my $txnid,my $date,my $custid,my $amount, my $productc, my $subc, +my $city, my $state, my $mode) = split(","); my $key_to_reduce = join ".", "$subc", "$state"; print "$key_to_reduce\t$amount\n"; }

This?

while ( <MYFILE> ) { # not needed if you don't use last field # chomp; # one 'my' for a list; grab only the needed fields my ($amount, $subc, $state) = (split/,/)[3,5,7]; # no need for join: my $key_to_reduce = "$subc.$state"; print "$key_to_reduce\t$amount\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1039567]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2021-09-26 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?