Re: Using reference or throw valuables to sub ?

2004-09-08 Thread Flemming Greve Skovengaard
Bee wrote:
Say I have an array that carries at least 2mb data or 70mb max,
but in my code, I want to throw this array to another sub ( within 
the same package )for further  operations . so, which one I would 
better to use and what's the reason ?

gosub [EMAIL PROTECTED]
or
gosub @array 

Is that if I  throw the array to another sub also means the 
array would be copied and then pass to the target sub ?
Yes
while reference is using the same data in system memory?
Yes
Thanks


--
Flemming Greve Skovengaard   FAITH, n.
a.k.a Greven, TuxPower   Belief without evidence in what is told
<[EMAIL PROTECTED]>  by one who speaks without knowledge,
4112.38 BogoMIPS of things without parallel.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Using reference or throw valuables to sub ?

2004-09-08 Thread Jenda Krynicky
From: "Bee" <[EMAIL PROTECTED]>
> Say I have an array that carries at least 2mb data or 70mb max,
> but in my code, I want to throw this array to another sub ( within the
> same package )for further  operations . so, which one I would better
> to use and what's the reason ?
> 
> gosub [EMAIL PROTECTED]
> or
> gosub @array 

Definitely the first.
 
> Is that if I  throw the array to another sub also means the 
> array would be copied and then pass to the target sub ?
> while reference is using the same data in system memory?

The first version passes just the reference to the already existing 
array while the second creates a new array containing aliases to the 
items in the original array. This means that unless you do

sub foo {
my @array = @_;
...

you do not have copies of the elements in the array, but you do force 
Perl to create an array. I'm not sure how many bytes do the aliases 
take, but if the array has many elements you probably do not want to 
do that.

The
my @array = @_;
in the sub would create a copy of the array and the values.

Jenda
P.S.: You do not throw values to subs, you pass them. You only throw 
exceptions.
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Using reference or throw valuables to sub ?

2004-09-08 Thread Thomas Bätzler
Bee <[EMAIL PROTECTED]> asked:
> Is that if I  throw the array to another sub also means the 
> array would be copied and then pass to the target sub ?
> while reference is using the same data in system memory?

Yes. Use references, unless you need to munge the array in the
sub you're calling.

HTH,
Thomas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Using reference or throw valuables to sub ?

2004-09-08 Thread Bee
Thank you guys for clearing my concept, I know what to do now !




- Original Message - 
From: "Jenda Krynicky" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, September 08, 2004 8:45 PM
Subject: Re: Using reference or throw valuables to sub ?


> From: "Bee" <[EMAIL PROTECTED]>
> > Say I have an array that carries at least 2mb data or 70mb max,
> > but in my code, I want to throw this array to another sub ( within the
> > same package )for further  operations . so, which one I would better
> > to use and what's the reason ?
> > 
> > gosub [EMAIL PROTECTED]
> > or
> > gosub @array 
> 
> Definitely the first.
>  
> > Is that if I  throw the array to another sub also means the 
> > array would be copied and then pass to the target sub ?
> > while reference is using the same data in system memory?
> 
> The first version passes just the reference to the already existing 
> array while the second creates a new array containing aliases to the 
> items in the original array. This means that unless you do
> 
> sub foo {
> my @array = @_;
> ...
> 
> you do not have copies of the elements in the array, but you do force 
> Perl to create an array. I'm not sure how many bytes do the aliases 
> take, but if the array has many elements you probably do not want to 
> do that.
> 
> The
> my @array = @_;
> in the sub would create a copy of the array and the values.
> 
> Jenda
> P.S.: You do not throw values to subs, you pass them. You only throw 
> exceptions.
> = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
> When it comes to wine, women and song, wizards are allowed 
> to get drunk and croon as much as they like.
> -- Terry Pratchett in Sourcery
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>