Raya4505 has asked for the wisdom of the Perl Monks concerning the following question:
Ok, I did find this thread on here already, but situation is a little different and that is the kicker for me. I am making a hash from two columns from a delimited text file. However, I need one of those items to be renamed and then print the renamed item and not the original values that were pasted in from the text file. Code below. Thank you in advance for your amazing help. I'm super new so please be very gentle...and simple.
my @ComplicationsSurgicalProcedMedCare_238 = qw(27661 27783 27788 2853 + 28741); my @SuperficialInjuryContusion_239 = qw(9062 9063 9100 9101); my %diags = ( "Complications of surgical procedures or medical care" =>\@Complicatio +nsSurgicalProcedMedCare_238, "Superficial injury; contusion" =>\@SuperficialInjuryContusion_239, ); my %Diag; my $file = "2009.txt"; open my $fh, "<", $file or die "Can't open $file: $!"; while (<$fh>) { my ($RID, $DiagCode) = split; push @{ $Diag{$RID} }, $DiagCode; } #Print items of array to text file open my $fh1, '>', "Output by RID.txt" or die "Cannot open output.txt: + $!"; foreach (my $RID) { print $fh1 Dumper(\%Diag); } my @Search = <$fh1> ; my %frequency; for my $Search (@Search) { for my $diag ( keys %diags ) { if( my @found = grep { $_ eq $Search } @{$diags{$diag}} ) { my $found = join ",", @found; print "Diagnosis Found: $diag, $found\n"; $frequency{$Search}++; } } } foreach (@Search) { print $fh1 "$_\n"; # Print each entry in our array to the file } close $fh1; #count how many times a variable is repeated my %counts = (); for (@Search) { $counts{$_}++; } print "\n Completed!\n";
So, I feel like I have all the pieces there, they aren't connecting though. I also would love for the output to look like this in one text file:
RID1 {DiagName: DiagCode1, count (for that specific RID)
DiagName: DiagCode2, count (for that specific RID)
}RID2 {DiagName:DiagCode3, count (for that specific RID)
DiagName:DiagCode4, count (for that specific RID)
}So, if the DiagCode repeats for different RIDs it will only give you the count for that particular RID. If someone has any ideas, I would be so grateful! Thank you!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Putting Hash values into an array
by Athanasius (Archbishop) on Feb 28, 2014 at 02:30 UTC | |
by flexvault (Monsignor) on Feb 28, 2014 at 08:35 UTC | |
by Athanasius (Archbishop) on Feb 28, 2014 at 08:52 UTC | |
by Raya4505 (Novice) on Feb 28, 2014 at 14:09 UTC | |
by Athanasius (Archbishop) on Mar 01, 2014 at 13:53 UTC | |
by Raya4505 (Novice) on Mar 05, 2014 at 15:04 UTC | |
by Athanasius (Archbishop) on Mar 06, 2014 at 02:52 UTC | |
| |
by Raya4505 (Novice) on Mar 04, 2014 at 13:53 UTC |