Re: returning arrays

2016-02-21 Thread lee
Nathan Hilterbrand writes: > On 01/25/2016 05:13 PM, lee wrote: >> Paul Johnson writes: >> >>> On Mon, Jan 25, 2016 at 12:24:04AM +0100, lee wrote: Paul Johnson writes: >>> [...] Consider with these examples that an expression like

Re: returning arrays

2016-02-21 Thread lee
Kent Fredric writes: > On 26 January 2016 at 12:02, Nathan Hilterbrand wrote: >> return wantarray() ? ($a, $b) : [$a, $b]; >> >> In a list context, you get back a list.. otherwise you get back a reference >> to a list. Might not be what you want,

Re: returning arrays

2016-01-25 Thread Paul Johnson
On Mon, Jan 25, 2016 at 12:24:04AM +0100, lee wrote: > Paul Johnson writes: > > > On Sun, Jan 24, 2016 at 05:44:14PM +0200, Shlomi Fish wrote: > >> Hi lee, > >> > >> On Sun, 24 Jan 2016 13:11:37 +0100 > >> lee wrote: > >> > >> > Paul Johnson

Re: returning arrays

2016-01-25 Thread Nathan Hilterbrand
On 01/25/2016 05:13 PM, lee wrote: Paul Johnson writes: On Mon, Jan 25, 2016 at 12:24:04AM +0100, lee wrote: Paul Johnson writes: [...] Consider with these examples that an expression like (1, 3) might unexpectedly evaluate to 3, and you start to think that

Re: returning arrays

2016-01-25 Thread lee
Shlomi Fish writes: > Hi lee, > > I should note that it is my impression that you are far too needy in your > enquiring, and I'm starting to lose patience. > > On Mon, 25 Jan 2016 00:11:43 +0100 > lee wrote: > >> Shlomi Fish

Re: returning arrays

2016-01-25 Thread lee
Paul Johnson writes: > On Mon, Jan 25, 2016 at 12:24:04AM +0100, lee wrote: >> Paul Johnson writes: > [...] >> Consider with these examples that an expression like (1, 3) might >> unexpectedly evaluate to 3, and you start to think that you don't like >> things

Re: returning arrays

2016-01-25 Thread Kent Fredric
On 26 January 2016 at 12:02, Nathan Hilterbrand wrote: > return wantarray() ? ($a, $b) : [$a, $b]; > > In a list context, you get back a list.. otherwise you get back a reference > to a list. Might not be what you want, though. > > Works with arrays, too.. > > my @anarray =

Re: returning arrays

2016-01-25 Thread Shlomi Fish
Hi lee, I should note that it is my impression that you are far too needy in your enquiring, and I'm starting to lose patience. On Mon, 25 Jan 2016 00:11:43 +0100 lee wrote: > Shlomi Fish writes: > > >> > > >> > In scalar context the comma operator

Re: returning arrays

2016-01-24 Thread lee
Paul Johnson writes: > On Tue, Sep 09, 2014 at 03:12:00PM -0700, Jim Gibson wrote: >> >> On Sep 9, 2014, at 2:57 PM, Shawn H Corey wrote: >> >> > On Tue, 09 Sep 2014 23:09:52 +0200 >> > lee wrote: >> > >> >> my $i = 1; >> >> my $f = 2.5; >> >> my $s =

Re: returning arrays

2016-01-24 Thread Shlomi Fish
Hi lee, On Sun, 24 Jan 2016 13:11:37 +0100 lee wrote: > Paul Johnson writes: > > > On Tue, Sep 09, 2014 at 03:12:00PM -0700, Jim Gibson wrote: > >> > >> On Sep 9, 2014, at 2:57 PM, Shawn H Corey wrote: > >> > >> > On Tue, 09 Sep 2014 23:09:52 +0200 > >>

Re: returning arrays

2016-01-24 Thread Paul Johnson
On Sun, Jan 24, 2016 at 05:44:14PM +0200, Shlomi Fish wrote: > Hi lee, > > On Sun, 24 Jan 2016 13:11:37 +0100 > lee wrote: > > > Paul Johnson writes: > > > > > > In scalar context the comma operator evaluates its left-hand side, > > > throws it away and returns

Re: returning arrays

2016-01-24 Thread Shlomi Fish
On Sun, 24 Jan 2016 20:03:29 +0100 Paul Johnson wrote: > On Sun, Jan 24, 2016 at 05:44:14PM +0200, Shlomi Fish wrote: > > Hi lee, > > > > On Sun, 24 Jan 2016 13:11:37 +0100 > > lee wrote: > > > > > Paul Johnson writes: > > > > > > > > In

Re: returning arrays

2016-01-24 Thread lee
Paul Johnson writes: > On Sun, Jan 24, 2016 at 05:44:14PM +0200, Shlomi Fish wrote: >> Hi lee, >> >> On Sun, 24 Jan 2016 13:11:37 +0100 >> lee wrote: >> >> > Paul Johnson writes: >> > > >> > > In scalar context the comma operator evaluates its

Re: returning arrays

2016-01-24 Thread lee
Shlomi Fish writes: >> > >> > In scalar context the comma operator evaluates its left-hand side, >> > throws it away and returns the right-hand side. >> >> What is the useful use for this operator? >> > > Well, I believe its use was originally inherited from >

Re: returning arrays

2014-09-09 Thread lee
Jim Gibson jimsgib...@gmail.com writes: On Sep 8, 2014, at 3:13 PM, lee wrote: Shawn H Corey shawnhco...@gmail.com writes: On Mon, 18 Aug 2014 16:17:53 +0800 # or sub myfunc { return [ 1, 2, 3 ]; } Is there a difference to sub myfunc { return ( 1, 2, 3 ); } The first

Re: returning arrays

2014-09-09 Thread Shawn H Corey
On Tue, 09 Sep 2014 23:09:52 +0200 lee l...@yun.yagibdah.de wrote: my $i = 1; my $f = 2.5; my $s = 'string'; my $list = (1, 2, 3); No, the count of items in the list gets stored in $list: $list == 3 my $list_reference = [(1, 2, 3)]; my $dereferenced_list = $@list_reference; my

Re: returning arrays

2014-09-09 Thread John SJ Anderson
On Tue, Sep 9, 2014 at 2:57 PM, Shawn H Corey shawnhco...@gmail.com wrote: Lists are sequences used by Perl. They are very short lived, seldom longer than one statement. The way I've always liked to explain this is that arrays are the containers you use to store a list. As Shawn says, a list

Re: returning arrays

2014-09-09 Thread Jim Gibson
On Sep 9, 2014, at 2:09 PM, lee wrote: Jim Gibson jimsgib...@gmail.com writes: On Sep 8, 2014, at 3:13 PM, lee wrote: Shawn H Corey shawnhco...@gmail.com writes: On Mon, 18 Aug 2014 16:17:53 +0800 # or sub myfunc { return [ 1, 2, 3 ]; } Is there a difference to sub myfunc {

Re: returning arrays

2014-09-09 Thread Jim Gibson
On Sep 9, 2014, at 2:57 PM, Shawn H Corey wrote: On Tue, 09 Sep 2014 23:09:52 +0200 lee l...@yun.yagibdah.de wrote: my $i = 1; my $f = 2.5; my $s = 'string'; my $list = (1, 2, 3); No, the count of items in the list gets stored in $list: $list == 3 Unless the thing on the

Re: returning arrays

2014-09-09 Thread Uri Guttman
On 09/09/2014 06:01 PM, John SJ Anderson wrote: On Tue, Sep 9, 2014 at 2:57 PM, Shawn H Corey shawnhco...@gmail.com wrote: Lists are sequences used by Perl. They are very short lived, seldom longer than one statement. The way I've always liked to explain this is that arrays are the containers

Re: returning arrays

2014-09-09 Thread Shawn H Corey
On Tue, 9 Sep 2014 15:05:58 -0700 Jim Gibson jimsgib...@gmail.com wrote: Some people make a distinction between 'list' and 'array'. A list is a sequence of scalar values indexed by an integer. An array is a variable whose value is a list (or something like that -- I don't really distinguish

Re: returning arrays

2014-09-09 Thread Paul Johnson
On Tue, Sep 09, 2014 at 03:12:00PM -0700, Jim Gibson wrote: On Sep 9, 2014, at 2:57 PM, Shawn H Corey wrote: On Tue, 09 Sep 2014 23:09:52 +0200 lee l...@yun.yagibdah.de wrote: my $i = 1; my $f = 2.5; my $s = 'string'; my $list = (1, 2, 3); No, the count of items in the

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

2014-09-08 Thread lee
Shawn H Corey shawnhco...@gmail.com writes: On Mon, 18 Aug 2014 16:17:53 +0800 Ken Peng o...@dnsbed.com 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

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 shawnhco...@gmail.com writes: On Mon, 18 Aug 2014 16:17:53 +0800 Ken Peng o...@dnsbed.com wrote: sub myfunc { my @x=(1,2,3); return \@x; } # or, sub myfunc { my @x=(1,2,3); return [@x]; } # or sub myfunc {

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 l...@yun.yagibdah.de wrote: Shawn H Corey shawnhco...@gmail.com writes: On Mon, 18 Aug 2014 16:17:53 +0800 Ken Peng o...@dnsbed.com wrote: sub myfunc { my @x=(1,2,3); return \@x; } # or, sub myfunc { my @x=(1,2,3);

Re: Returning arrays from subroutines... how?

2003-06-02 Thread Ken Tozier
Thanks for answering David, Jeff and Beau. My script works like a charm now. Ken -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Returning arrays from subroutines... how?

2003-06-01 Thread Ken Tozier
I'm sure this is an easy one but after Googling for hours, I still don't get it. Given the following subroutine, how do I return the result array? Nothing I try works. sub GetMarmots { @result = (); $result{'steppe marmot '} = 4; $result{'himalayan marmot'} = 3;

Re: Returning arrays from subroutines... how?

2003-06-01 Thread jeff loetel
Ken, your mixing your @ with your % Try this: #!/usr/bin/perl GetMarmots; sub GetMarmots { %result = (); $result{'steppe marmot'} = 4; $result{'himalayan marmot'} = 3; $result{'mongolian marmot'} = 1; $result{'woodchuck'} = 6; return %result; } foreach (keys %result)

Re: Returning arrays from subroutines... how?

2003-06-01 Thread Beau E. Cox
- Original Message - From: Ken Tozier [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, May 31, 2003 5:24 PM Subject: Returning arrays from subroutines... how? I'm sure this is an easy one but after Googling for hours, I still don't get it. Given the following subroutine, how

RE: Returning arrays from subroutines... how?

2003-06-01 Thread Charles K. Clarkson
jeff loetel [EMAIL PROTECTED] wrote: : Try this: : : #!/usr/bin/perl : : GetMarmots; : : sub GetMarmots { : %result = (); : $result{'steppe marmot'} = 4; : $result{'himalayan marmot'} = 3; : $result{'mongolian marmot'} = 1; : $result{'woodchuck'} = 6; : return %result;