return the list content

2014-08-18 Thread Ken Peng
Hello, sub myfunc { my @x=(1,2,3); return \@x; } # or, sub myfunc { my @x=(1,2,3); return [@x]; } which one is the better way to return the list content? And if the method is an instance method? Thanks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional

Re: return the list content

2014-08-18 Thread Paul Johnson
On Mon, Aug 18, 2014 at 04:17:53PM +0800, Ken Peng wrote: > Hello, > > sub myfunc { > my @x=(1,2,3); > return \@x; > } > > # or, > > sub myfunc { > my @x=(1,2,3); > return [@x]; > } > > which one is the better way to return the list conte

Re: return the list content

2014-08-18 Thread Shawn H Corey
On Mon, 18 Aug 2014 16:17:53 +0800 Ken Peng wrote: > sub myfunc { > my @x=(1,2,3); > return \@x; > } > > # or, > > sub myfunc { > my @x=(1,2,3); > return [@x]; > } # or sub myfunc { return [ 1, 2, 3 ]; } -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail:

Re: return the list content

2014-08-18 Thread John SJ Anderson
On Mon, Aug 18, 2014 at 1:38 AM, Paul Johnson wrote: > On Mon, Aug 18, 2014 at 04:17:53PM +0800, Ken Peng wrote: >> which one is the better way to return the list content? And if the >> method is an instance method? > > Functionally, the two are identical. The first is

Re: return the list content

2014-09-08 Thread Rob Dixon
On 18/08/2014 09:17, Ken Peng wrote: sub myfunc { my @x=(1,2,3); return \@x; } # or, sub myfunc { my @x=(1,2,3); return [@x]; } which one is the better way to return the list content? And if the method is an instance method? The first version of the subroutine is the best

Re: return the list content

2014-09-08 Thread Ken Peng
Since this is a shadow copy, I don't think the first array will be deleted completely. Isn't it? The second option creates the same array and populates it, but then copies it to another anonymous array, deletes the first array, and returns a reference to the copy. -- To unsubscribe, e-mail:

Re: return the list content

2014-09-10 Thread Rob Dixon
On 09/09/2014 02:20, Ken Peng wrote: The second option creates the same array and populates it, but then copies it to another anonymous array, deletes the first array, and returns a reference to the copy. Since this is a shadow copy, I don't think the first array will be deleted completely. I

Re: return the list content

2014-09-12 Thread Charles DeRykus
On Wed, Sep 10, 2014 at 4:18 AM, Rob Dixon wrote: > On 09/09/2014 02:20, Ken Peng wrote: >> >> >>> The second option creates the same array and populates it, but then >>> copies it to another anonymous array, deletes the first array, and >>> returns a reference to the copy. >> >> >> Since this is

Re: return the list content

2018-06-14 Thread Paul Johnson
On Mon, Aug 18, 2014 at 06:07:59AM -0700, John SJ Anderson wrote: On Mon, Aug 18, 2014 at 1:38 AM, Paul Johnson wrote: > On Mon, Aug 18, 2014 at 04:17:53PM +0800, Ken Peng wrote: >> which one is the better way to return the list content? And if the >> method is an instance metho

returning arrays (was: Re: return the list content)

2014-09-08 Thread lee
Shawn H Corey writes: > On Mon, 18 Aug 2014 16:17:53 +0800 > Ken Peng wrote: > >> sub myfunc { >> my @x=(1,2,3); >> return \@x; >> } >> >> # or, >> >> sub myfunc { >> my @x=(1,2,3); >> return [@x]; >> } > > # or > > sub myfunc { > return [ 1, 2, 3 ]; > } Is there a difference to su

Re: returning arrays (was: Re: return the list content)

2014-09-08 Thread Jim Gibson
On Sep 8, 2014, at 3:13 PM, lee wrote: > Shawn H Corey writes: > >> On Mon, 18 Aug 2014 16:17:53 +0800 >> Ken Peng wrote: >> >>> sub myfunc { >>> my @x=(1,2,3); >>> return \@x; >>> } >>> >>> # or, >>> >>> sub myfunc { >>> my @x=(1,2,3); >>> return [@x]; >>> } >> >> # or >> >> sub myfu

Re: returning arrays (was: Re: return the list content)

2014-09-08 Thread Shawn H Corey
On Tue, 09 Sep 2014 00:13:13 +0200 lee wrote: > Shawn H Corey writes: > > > On Mon, 18 Aug 2014 16:17:53 +0800 > > Ken Peng wrote: > > > >> sub myfunc { > >> my @x=(1,2,3); > >> return \@x; > >> } > >> > >> # or, > >> > >> sub myfunc { > >> my @x=(1,2,3); > >> return [@x]; > >> } > >