Rocky Allen wrote:
> hi Y'all,
>
> I am writing a backup script for an Oracle Database server on Linux. It
> is very long so I only included the code I need help with here. The
> entire script is published here. http://bobotheclown.org/scripts/comlang
>
> I am trying to turn this code into a subroutine:
>
> open(FH13, ">$contentsfile") or die "Couldnt get FH13:$!";
> print FH13 @joblog;
> print FH13 "\n";
> print FH13 "breakpointforrecover\n";
> print FH13 "\n";
> print FH13 @intersection;
> print FH13 "\n";
> print FH13 "\n";
> print FH13 @splitnames;
> close FH13;
>
> My question is this:
>
> Since I have to pass all of those arrays into the subroutine as @_, how
> can I tell when one ends and the next begins?
Don't pass the arrays - pass references to them:
sub print_to_file {
my $contentsfile = shift;
my ($joblog, $intersection, $splitnames) = @_;
open my $FH13, '>', $contentsfile or
die "Could not open $contentsfile: $!\n";
my $old_fh = select $FH13;
print @$joblog, "\n";
print "breakpointforrecover\n\n";
print @$intersection, "\n\n";
print @splitnames;
select $old_fh;
}
print_to_file($filename, \@joblog, \@intersection, \@splitnames);
alternatively, use a prototype to auto-create the references for you:
sub print_to_file ($\@\@\@) {
#... all code as before
}
print_to_file($filename, @joblog, @intersection, @splitnames);
For more information:
perldoc perlsub
perldoc perlreftut
perldoc perlref
perldoc -f select
Paul Lalli