in reply to passing multiple items to a subroutine
Welcome to the monastery. When passing multiple non-scalar variables into a sub the arguement list gets flattened into a scalar list. This is why you must use references. perlref should be a good starting place to learn about references. FYI when returning values from a sub, the same rules apply.
i.e. a sub that you needed to pass two arrays and a hash to would look like this.
Forgive my previous answer. You do not need to use the shift function in conjuction with assigning the argument list. shift with out any arguments will take the first element off of the @_ array and return it as a scalar. The code
my ($xarray,$values,$xlabel,$ylabel,$title) = shift(@_); does not do what you expect. Two ways of doing it are
This is really a bad way of getting this done...for that.. God gave us this method my ($xarray,$values,$xlabel,$ylabel,$title) = @_; This puts your scalars in list context and assigns the @_ list to it matching indexes to the order of the decalared variables. This is a good general purpose way to get this done.my $xarray = shift; my $xarray = shift; my $values = shift; my $xlabel = shift; my $ylabel = shift; my $title = shift;
Not trying to nit pick at all .. but just trying to point out something that may not be what you had intended.push @data,$_ for @{$xarray}; push @data,$_ for @{$values};
in the top of your script. For me its a good bonehead error catcher. Alot of the silly things we do get caught by those two pragma. Hope some of that was useful... again sorry for previous answer.use strict; use warnings;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
passing multiple items to a subroutine
by tommycahir (Acolyte) on Mar 08, 2004 at 15:38 UTC | |
by Grygonos (Chaplain) on Mar 08, 2004 at 16:21 UTC |