in reply to Get CSV data and convert it to other format data dynamically.
Here is my input on it, which I am pretty new to hashes as well so please keep that in mind ;)
use strict; use warnings; use Data::Dumper; my %hash = (); my $i = 0; while (<DATA>) { chomp; my ( $sec_id, $Initial_shares ) = split( /,/, $_ ); $hash{secid}{$i} = $sec_id; $hash{init_sh}{$i} = $Initial_shares; $i++; } #print Dumper \%hash; foreach my $outter_key ( keys %hash ) { print "$outter_key => {\n"; while ( my ( $inner_key, $inner_value ) = each $hash{$outter_key} +) { print "\t\t" . qq('$inner_key') . " => " . qq('$inner_value') +. "\n"; } print "};\n\n"; } __DATA__ 002826,3777 0028262,3777 0028262,3777 0028262,3777 0028262,3777 0028262,3777
Outputs:
init_sh => { '4' => '3777' '1' => '3777' '3' => '3777' '0' => '3777' '2' => '3777' '5' => '3777' }; secid => { '4' => '0028262' '1' => '0028262' '3' => '0028262' '0' => '002826' '2' => '0028262' '5' => '0028262' };
This method looks like it would be a sure fire way to keep track of what belonged to what as well.
EDIT: I dont know why, but I thought OP was looking for a solution with hashes... anyway on a side note, while I was messing around with this, I did figure out another way to load modules haha;
EDIT: Updated code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Get CSV data and convert it to other format data dynamically.
by Tux (Canon) on Aug 25, 2015 at 06:44 UTC |