Ok, what I'd expect is that printing $output within the sub will result in the contents of the file being in there. What I'm finding, however, is that I get something like "SCALAR(0x828c810)interface blah ip address 1.2.3.4 255.255.255.255" And after exiting the loop, $template is empty. Obviously what's happening is that I've not referenced it properly and the $output variable actually has the scalar reference as its value rather than being a reference to the original scalar. What have I done wrong?sub file_expansion { my ($output, $input) = @_; my $test = $output; # For testing whether I need to append + to an array or a scalar# while (<@$input>) { if (-e $_) { open (FILE, "< $_"); my @lines = <FILE>; foreach my $line (@lines) { $_ = $test; if (/SCALAR/) { $output .= $line; } else { push @$output, $line; } } } else { print "<<ERROR: File \'$_\' doesn't exist or c +an't be read.>>"; } } } @temp_fyle = "/home/monkey/list_of_commands"; (looks like below: interface blah ip address 1.2.3.4 255.255.255.255 ) &file_expansion(\$template,\@temp_fyle);
In reply to referencing question by bonoboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |