in reply to referencing question

When passing parameters, you want to pass scalars - which means you want to pass:
* scalars as themselves * each array as an array reference (a reference is a scalar) * each hash as a hash reference (a reference is a scalar)
so
1. there is no reason to pass a reference to $template(a scalar) to the subroutine - why not just pass $template? Forget about the reference - then in the subroutine you can do my ($output, $input) = @_; and just use $output in the subroutine, instead of having to use $$output. 2. when you pass \@temp_fyle in the call to subroutine file_expansion, that's fine. This is just my preference, but IMHO it helps keep your code simpler and more understandable if you name variables consistent with what they contain. For example, in subroutine file_expansion, name the imcoming parameter that is a reference to the array what it is - a reference, like this: my ($output, $input_arrayref) = @_; or maybe even better my ($output, $temp_fyle_arrayref) = @_; Then, since you can actually use the reference to point at array elements (instead of having to dereference the array reference into an array), you can do something like this print "first element is $temp_fyle_arrayref->[0]\n"; to refer to the 1st element of the array, instead of having to do my @new_array = @$temp_fyle_arrayref; my $first = @new_array[0]; print "first element is $first\n"; which takes more memory since you are creating another array(@new_array).
HTH.

Replies are listed 'Best First'.
Re: Re: referencing question
by synistar (Pilgrim) on Nov 06, 2003 at 23:23 UTC
    hmerrill: I was under the impression that if you had very large scalar (e.g. $template contains a 100kb template) it was more efficient to pass a reference than to pass the whole scalar, since no memory is being copied. Or am I confused on this point?
      No, your impression is probably correct - I've never really used scalars with really *large* values, so that's probably why I didn't think of that. In that case, you *should* probably pass a reference to the scalar like you were doing in the first place. Sorry if I confused you.