MC logo

Passing Subroutine Arguments (Answer)

  Practice Problems

The program
sub bozo {
    my ($this, $that) = @_;

    print "[$this] [$that]\n";
    print "@_\n\n";
}

bozo "this", "that", "the other";

@dip = ("a", "b", "c");
bozo("A", @dip, "Z");

bozo "10";

bozo (("T"), ("h"), ("a", "t"));
prints
[this] [that]
this that the other

[A] [a]
A a b c Z

[10] []
10

[T] [h]
T h a t

In all cases, whatever you send is flattened into a single array and sent as @_. The first two members of @_ wind up in $this and $that. When only one argument is sent, $that is the empty string.
<<Patterns I Question