in reply to variable expansion
(Since this looks a lot like homework, I won't elaborate on the sub read_all_lines_into_an_array().my @lines = &read_all_lines_into_an_array(); # Here you set the values for the variables you want # interpolated later... eval qq{print "$_\n"} for @lines;
As perl will automatically interpolate the variables for you. However, this approach is *very* dangerous, as you would be trusting "code" coming from outside your script without proper sanity checking. Although the code would only go as far as a print, I would not consider this good programming practice. If you only care for simple scalar interpolation, you can probably do something along these lines:
Provided that you have a list of the scalars to interpolate.for my $line (@lines) { for my $var ('@scalars_to_interpolate) { eval qq{\$line =~ s/\\$var/$var/g}, "\n"; } print $line, "\n"; }
Regards.
|
|---|