mmittiga17 has asked for the wisdom of the Perl Monks concerning the following question:
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.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"; }
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Please help with Hash Key,value issue
by CountZero (Bishop) on Mar 11, 2009 at 17:47 UTC | |
|
Re: Please help with Hash Key,value issue
by toolic (Bishop) on Mar 11, 2009 at 17:52 UTC | |
by mmittiga17 (Scribe) on Mar 11, 2009 at 18:52 UTC | |
by bellaire (Hermit) on Mar 11, 2009 at 20:40 UTC |