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
|