#!/bin/perl use strict; use warnings; my $cfg_file = "/tmp/Allcontrol.csv"; read_control($cfg_file); sub read_control { my ($cfg_file) = @_; ## This is a internal module to parse and giveout data as hashref my $ctrl_data = ImportData(); my @IndxData; foreach (keys %$ctrl_data){ my $ExchangeTag = $ctrl_data->{$_}->{Tag}; my $Marker = $ctrl_data->{$_}->{Marker}; my $Name = $ctrl_data->{$_}->{Name}; my $Currency = $ctrl_data->{$_}->{Currency}; my $Industry = $ctrl_data->{$_}->{Industry}; my $SuperSector = $ctrl_data->{$_}->{SuperSector}; my $Sector = $ctrl_data->{$_}->{Sector}; my $Ind_Sec_Curr= $ctrl_data->{$_}->{Sub Currencies}; # Parse single/multiple currencies if(defined $Currency){ my @Currency = split /\|/, $Currency; foreach my $corecurr (@Currency){ my $row = {}; my $curr = substr($corecurr, 0,1); $curr = substr($corecurr, 1,1) if($curr eq "9"); if($curr eq "U"){ $row->{ExchangeTag} = $ExchangeTag; }else { $row->{ExchangeTag} = $ExchangeTag . "_" . $curr; } $row->{Name} = $Name; $row->{Currency} = $corecurr; $row->{SectorCurrency} = $Ind_Sec_Curr; $row->{SourceID} = $Marker; push @IndxData, $row; } } #Parse single/multiple industries if (defined $Industry and $Industry ne ""){ my @industry = split /\|/, $Industry; foreach my $ind (@industry){ my $row = {}; $row->{Name} = $Name; $row->{Currency} = $Currency; $row->{SectorCurrency} = $Ind_Sec_Curr; $row->{IndustryCode} = $ind; $row->{SourceID} = $Marker; $row->{ExchangeTag} = $ExchangeTag . $ind; push @IndxData, $row; } } #Parse multiple/single Sectors if (defined $Sector and $Sector ne ""){ my @sector = split /\|/, $Sector; foreach my $sect (@sector){ my $row = {}; $row->{Name} = $Name; $row->{Currency} = $Currency; $row->{SectorCurrency} = $Ind_Sec_Curr; $row->{SectorCode} = $sect; $row->{SourceID} = $Marker; $row->{ExchangeTag} = $ExchangeTag . $sect; push @IndxData, $row; } } } die Dumper @IndxData; }