Ask a Question related to PERL Beginners, Design and Development.
-
Mike Blezien #1
passing an array
Hello,
what is the best way to pass an array to a sub routine,
IE.
my @fields = qw(one two three);
send_array(@fields);
sub send_array {
my @ary = @_;
# do stuff here....
}
is this the most effective way to pass an array to sub
routine or is there a better way to do this.
thx's
--
Mike<mickalo>Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
[url]http://www.thunder-rain.com[/url]
Quality Web Hosting
[url]http://www.justlightening.net[/url]
MSN: [email]mickalo@thunder-rain.com[/email]
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Mike Blezien Guest
-
Passing value to Array
If I've got x = "test5" How can I put the value of x to Array list=; I'd try to use ---> list= but is not work. -
passing array in the url
Hello there, I am unable to pass an array thought he url. Even the most simple array as in the code: $test = array(1,2,3,4); echo "<a... -
Array passing problem...
Hoping someone can point out my more than likely simple mistake here... function getBranchArray($desig,$branchArray){ $arrayResult =... -
Passing Array Via CGI.pm
Hello all, I'm a Perl newbie here and have a quick question regarding CGI.pm. I have a CGI script that passes an array to another CGI script as... -
Passing a keyed Array via php.
Hi ACteon! On 18 Aug 2003 19:17:23 -0700, acteon@yahoo.com (Acteon) wrote: Use - form method="post" - $_POST etc. - no books as they are... -
James Edward Gray II #2
Re: passing an array
On Dec 9, 2003, at 8:49 PM, Mike Blezien wrote:
That depends on how you define "effective". The way you showed is the> Hello,
>
> what is the best way to pass an array to a sub routine,
> IE.
>
> my @fields = qw(one two three);
>
> send_array(@fields);
>
>
> sub send_array {
> my @ary = @_;
> # do stuff here....
> }
>
> is this the most effective way to pass an array to sub routine or is
> there a better way to do this.
easiest. References are probably better in some respects though, if
you don't mind the complications:
my @array = qw(1 2 3);
my @other_array = qw(dog cat pig);
send_array(\@array, \@other_array);
sub send_array {
my($nums, $anims) = @_;
# do stuff with references here, for example
print $nums->[1], ' ', $anims->[2], "\n"; # prints "2 pig"
}
Hope that helps.
James
James Edward Gray II Guest
-
Mike Blezien #3
Re: passing an array
Thanks James,
passing as a reference was basically what I was trying to
recall,.... your example made that clear :)
--
Mike<mickalo>Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
James Edward Gray II wrote:> On Dec 9, 2003, at 8:49 PM, Mike Blezien wrote:
>>>> Hello,
>>
>> what is the best way to pass an array to a sub routine,
>> IE.
>>
>> my @fields = qw(one two three);
>>
>> send_array(@fields);
>>
>>
>> sub send_array {
>> my @ary = @_;
>> # do stuff here....
>> }
>>
>> is this the most effective way to pass an array to sub routine or is
>> there a better way to do this.
>
> That depends on how you define "effective". The way you showed is the
> easiest. References are probably better in some respects though, if you
> don't mind the complications:
>
> my @array = qw(1 2 3);
> my @other_array = qw(dog cat pig);
>
> send_array(\@array, \@other_array);
>
> sub send_array {
> my($nums, $anims) = @_;
> # do stuff with references here, for example
>
> print $nums->[1], ' ', $anims->[2], "\n"; # prints "2 pig"
> }
>
> Hope that helps.
>
> James
>
>
>Mike Blezien Guest
-
Bob Showalter #4
RE: passing an array
Mike Blezien wrote:
You can't pass an array to a sub. You can only pass a list of scalars.> Hello,
>
> what is the best way to pass an array to a sub routine, IE.
Whatever you passed ends up in @_. There's no way for the sub to know how>
> my @fields = qw(one two three);
>
> send_array(@fields);
>
>
> sub send_array {
> my @ary = @_;
this data was passed, if it matters.
If your sub just needs a list of values, what you've done is fine. If your> # do stuff here....
> }
>
> is this the most effective way to pass an array to sub
> routine or is there a better way to do this.
sub somehow needs to know about the @fields array, perhaps to modify it or
add or remove elements, you have to pass an array reference. Then you
manipulate the array via the reference inside the sub.
Bob Showalter Guest



Reply With Quote

