in reply to Subroutine Behaviour

@_ does what you want in string context as long as you pass only one argument. It is interpreted as the concatenation of all the arguments.

When you compare @_ to 0 or 1 you're in scalar context and @_ is interpreted as the number of arguments.

You could use $_[0] in place of @_ but it's probably better in the long run to start your subroutine with something like my $input=shift; and replace @_ by $input everywhere.

Perl is very context-dependent. You'll get bitten by this a few times before you get the hang of it.

Replies are listed 'Best First'.
Re^2: Subroutine Behaviour
by ysth (Canon) on Sep 26, 2004 at 06:42 UTC
    Just a slight correction; when you say "@_ does what you want in string context", you really mean "when interpolated in a string". Usually the term "string context" is used along with numeric or boolean context, which is a very different kind of context.