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!


In reply to Putting Hash values into an array by Raya4505

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.