Hello Raya4505,

Changing the script to handle diagnosis codes as strings rather than integers is not difficult. First, I’ve changed the contents of the input file “2009.txt” as follows:

Tom_Jones z9062 John_Smith V27783 Tom_Jones z9062 Jane_Brown 9100 Tom_Jones 28741 John_Smith z9062 Tom_Jones z9062 Jane_Brown z9062 Tom_Jones 28741 Jane_Brown c2853 Jane_Brown z9062 Tom_Jones 12345

Next, the script itself. You’ve already handled the most challenging part by changing the sort operator from <=> to cmp. The only other changes required are to the array initialisations and the printf formats:

  1. For the array initialisations, you need to quote the strings (because barewords are not allowed under strict 'subs'):

    my @ComplicationsSurgicalProcedMedCare_238 = ( 27661, 'V27783', 27788, + 'c2853', 28741); my @SuperficialInjuryContusion_239 = ('z9062', 9063, 9100, + 9101);

    Or, you can make use of Perl’s qw operator (on which, see: Quote Like Operators):

    my @ComplicationsSurgicalProcedMedCare_238 = qw(27661 V27783 27788 c28 +53 28741); my @SuperficialInjuryContusion_239 = qw(z9062 9063 9100 91 +01);
  2. The printf function format codes are as in C, and are detailed in the documentation for sprintf. %d formats its input as an integer, %s formats its input as a string. So this section of code:

    if (exists $DiagCodes{$_}) { printf $fh1 " %s: %d, %d\n", # *** Change here: ^ $DiagNames{ $DiagCodes{$_} }, $_, $Diags{$key}->{$_}; } else { printf $fh1 " Unrecognized code: %d\n", $_; # *** Change here: ^ }

    needs to be changed to:

    if (exists $DiagCodes{$_}) { printf $fh1 " %s: %s, %d\n", $DiagNames{ $DiagCodes{$_} }, $_, $Diags{$key}->{$_}; } else { printf $fh1 " Unrecognized code: %s\n", $_; }

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^7: Putting Hash values into an array by Athanasius
in thread 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.