"Tom Phoenix" schreef: > &silly_1($fred, $barney, $betty, $wilma); # four parameters > > my $params = [$fred, $barney, $betty, $wilma]; > &silly_2($params); # one parameter > > It looks promising. Is the second subroutine call more efficient than > the first one? Yes, it probably is. Does this style make the program > run any faster? Probably not; it takes about as long to build $params > as to call the sub with a list of parameters.
Internally the parameters of the first variant are *aliased* into @_. $ perl -wle' sub doit { $_[0] = "dirty" } my $foo = my $bar = "clean"; print "$foo, $bar"; doit $foo, $bar; print "$foo, $bar"; ' clean, clean dirty, clean In the second variant, the coder puts *copies* of the variables in an array, to be able to pass an array reference. $ perl -MData::Dumper -wle' my $foo = my $bar = "clean"; my $aref = [$foo, $bar]; $foo = "dirty"; print Dumper $aref; ' $VAR1 = [ 'clean', 'clean' ]; Each of these copied variables could hold multi-megabyte strings. But hey, it was a silly example, because only scalars are involved. The profit is in passing references of non-scalars. slightly_less_silly( [EMAIL PROTECTED], [EMAIL PROTECTED] ); ANFSCD: Tom, I keep wondering why do you often write the &-sigil where it is not needed? -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/