First off -- There's not really a need to use references in this instance. I'll rarely ref a $string, unless it's a blessed $string, or if length($string) == $reallyLarge. I understand your motivation, saving on the return. Just something to keep in mind.

That having been said, I suspect the issue is in your assignment (via ${shift()}). Since you wish to change the values of your references, I would make assignments through the reference itself. It appears that you're assigning the dereffed value of your stringrefs to scoped vars, not assigning local values to the referenence itself.

Strings are really easy to deref -- just add another $. I think your subroutine should probably look like this: (Line Numbers added)

1:sub read_template 2:{ 3: my($file_name_ref,$lines_in_ref) = @_; 4: my $line_cnt = 0; 5: open (INPUT, "$$file_name_ref") || 6: die "Can't open $$file_name_ref as input:$!"; 7: while (<INPUT>) 8: { 9: $line_cnt++; 10: $$lines_in_ref .= $_; 11: } 12: close (INPUT); 13: return($line_cnt); 14:}
A couple things to note:
  • The local variables are assigned to the actual references (line 3)
  • What we actually open (line 5) is the dereffed $file_name($$file_name_ref). I've modified the open/die logic -- save yourself some keystrokes. I've also passed the $OS_ERROR ($!) to the die to aid in diagnostics (line 5,6)
  • In line 10 -- we assign through the refernce, to the referent. ($$lines_in_ref)
  • HTH!

    ÅßÅ×ÅßÅ
    "It is a very mixed blessing to be brought back from the dead." -- Kurt Vonnegut


    In reply to Re: Sub Params as references by abaxaba
    in thread Sub Params as references by Maclir

    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.