Hi All,
I have this has I built by readying in a file:
my %userData;
open(inData, $data);
while (<inData>) {
chomp;
$line = $_;
if ($line =~/^GC/){
my $ACTNUM = substr $line, 11, 9 ;
my $ref = substr $line, 0, 3 ;
$userData{$ACTNUM}{$ref} = $line;
}
}
for my $ACTNUM (sort keys %userData) {
$line = $userData{$ACTNUM}{GCA};
$ACCTNUM = substr $line, 11, 9;
$FIRM_ID = substr $line, 660, 1;
$CURR = substr $line, 661, 3;
print "$CURR,$ACCTNUM,$FIRM_ID\n";
}
Problem is there can be multiple instances of the same key and value. However I am only able to return the first instance of it to print out.
What Am I doing wrong here?
Thanks
MM
Ok, I got myself to this point and am trying to read up on hash or arrays but. I cant figure out how to access each line I need to access as I was in my code sample.
This prints out what I want via Dumper:
my $data = "GCUS.GCUS";my %userData;open(inData, $data);while (<inData
+>) { chomp;
$line = $_;
if ($line =~/^GC/){
my $ACTNUM = substr $line, 11, 9 ;
my $ref = substr $line, 0, 3 ;
push @{ $userData{$ACTNUM} }, $ref = $line;
}
}
Here is where I get stuck and cant seem to understand the perl doc:
for $ACTNUM (sort keys %userData) {
#########GCA##############
my $line = $userData{$ACTNUM}{GCA};
$ACCTNUM = substr $line, 11, 9;
$FIRM_ID = substr $line, 660, 1;
$CURR = substr $line, 661, 3;