doran has asked for the wisdom of the Perl Monks concerning the following question:
Is that how it's done? Or is there some better way to determine whether I'm getting an array or an arrayref passed to the routine? Keep in mind I'm interested in how to get @array populated, not what is done with it or how it's returned.sub thinger{ return unless $_[0]; my @array; if((scalar @_) == 1){ return $_[0] unless ref($_[0]); @array = @{$_[0]}; } else{ @array = @_; } # Do something important sleep 30000; return wantarray ? @array : \@array; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Detecting Subroutine Input Type
by ysth (Canon) on May 03, 2004 at 06:14 UTC | |
|
Re: Detecting Subroutine Input Type
by Chady (Priest) on May 03, 2004 at 06:07 UTC | |
by Anonymous Monk on May 03, 2004 at 08:21 UTC | |
by doran (Deacon) on May 03, 2004 at 16:48 UTC | |
|
Re: Detecting Subroutine Input Type
by Mr. Muskrat (Canon) on May 03, 2004 at 06:11 UTC |