> [EMAIL PROTECTED] wrote: > > Ok fantastic, I totally understand that, and if there were going to be > > more than one thing passed, just insert $par2 = shift; on the next > > line and then the second argument is in $par2, I assume.....right?? > > Yes. > > You might also see it this way: > > my ($par1, $par2) = @_; > > The latter construct is not destructive of @_, while using shift() is. It > usually doesn't matter. >
Bob is giving correct, though terse answers. Subroutines receive their arguments in @_, in the special case that a subroutine acts as a method (aka in OOP (Object Oriented) Perl) then the first argument is either the object/instance/referent or the class name. In *most* cases this argument is considered different (in meaning) than the rest, because it is tacked on to the beginning by Perl automagically, so to retrieve the object/class and to restore the "user specified" argument list you generally want to C<shift> it off. So you end up with, sub method1 { my $self = shift; ... # now @_ contains only those arguments provided by the user } Along with the possibly more commonly used, sub method2 { my $self = shift; my ($arg1, $arg2) = @_; ... } sub method3 { my $self = shift; my (@args) = @_; ... } sub method4 { my $self = shift; my (%args) = @_; ... } And finally the above iterations with the more specific... sub method5 { my $class = shift; ... } Because Perl's rules in this area are loose the same applies to functional (non-OOP) techniques as well, though less idiomatically (IMHO). In other words less often will you want to shift off the arguments one at a time, or that the first argument is significantly different (in meaning) than the others. Having said that, it is not a rule and should not be taken as one, however can be applied when just making a template. Personally I would suggest adding a blank C<return> as the last line of the sub, and possibly providing a documentation template. To me these are more important than how you are going to accept your arguments. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>