bonoboy has asked for the wisdom of the Perl Monks concerning the following question:
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: referencing question
by gjb (Vicar) on Nov 06, 2003 at 12:59 UTC | |
by bonoboy (Sexton) on Nov 06, 2003 at 13:10 UTC | |
|
Re: referencing question
by hmerrill (Friar) on Nov 06, 2003 at 17:05 UTC | |
by synistar (Pilgrim) on Nov 06, 2003 at 23:23 UTC | |
by hmerrill (Friar) on Nov 07, 2003 at 13:42 UTC |