The problem in your is with extracting the sub parms from
@_. With
my $file_name = ${shift()};
my $lines_in = ${shift()};
you are copying your dereferenced references into new
local variables, which does not update the variables in the
caller. Try instead
sub read_template {
my $file_name = shift;
my $lines_in = shift;
my $line_cnt = 0;
if (!open (INPUT, "< $$file_name")) {
die "Can't open $file_name as input.";
} else {
while (<INPUT>) {
$line_cnt++;
$$lines_in .= $_;
}
close (INPUT);
}
return($line_cnt);
}
This approach keeps the references and updates the caller's
variables.
-Mark
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|