Two problems, one hidden by your order of definition.

The hidden one is from the use of an empty prototype. Properly ordered, your code would fail when you gave arguments to the sub. As it is, with warnings on, you would see the "Too late for prototype. . ." message.

When you say %paramhash = %$params1;, you are making a copy of the hash referenced by the argument. Manipulate directly through the reference to make your sub mutate the external structures.

sub upd_info { my ($hashref, $aryref) = @_; for my $key (keys %$hashref) { my $upd_flag = 0; for (sort @$aryref) { if ( /^\Q$key\E\s+(\w+)$/ ) { $upd_flag++; $hashref->{$key} .= $1; last; } } $upd_flag or $hashref->{$key} .= ' NONE'; } 1; }
I've taken care to make the variables lexical. There is no reason to have all those internal variables lurking in your namespace. Using strict and warnings will improve your code. Not knowing your intent, I copied your program logic directly.

After Compline,
Zaxo


In reply to Re: sub routine trouble by Zaxo
in thread sub routine trouble by tc1364

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.