in reply to Sending Information to Sub

Probably the easiest:
some("Foo", "Bar"); sub some { my ($one, $two) = @_; }
I am sure many others will most faster, cooler, and more elegant ways.. but that works, and is easy to read.

Update: Maybe I wasn't reading that right the first time.. I think you maybe wanted to send a scalar as one argument, and an array (just examples) as the other? In any event, it would work the same:

my @alphabet = ('A' .. 'Z'); some("Foo", @alphabet); sub some { my ($one, @alpha) = @_; }

Replies are listed 'Best First'.
Re: Re: Sne ding Information to Sub
by dvergin (Monsignor) on Jun 26, 2002 at 19:13 UTC
    This works as erasei describes:       some("Foo", @alphabet); ...but be careful. You will be tempted on another occasion to do one of the following:
    some(@alphabet, "Foo"); # BAD! some("Foo", @alphabet, @alpha2); # BAD!
    These fail because the first array encountered in the parameter list will gobble up all the remaining values.

    So you can do    some("Foo", @alphabet); and it will work because the only array in the list is the last parameter (same rule for hashes), but some would argue that it could be the beginning of a bad habit -- because later you have to be especially alert if you add another parameter for this sub.

    The option is to pass a reference to the array.

    some("Foo", \@alphabet); sub some { my ($one, $alpha_aref) = @_; my $letter_b = $alpha_aref->[1]; }
    Thus allowing you to pass as many arrays and hashes as you may need and mix them with scalars in any order.