Re: function return

2010-04-30 Thread Shawn H Corey
my ( $x, $y ) = ( $n ) = Function( $arg ); print '2nd: ', Dumper \$arg, \$n, \$x, \$y; my $count = ( $n ) = Function( $arg ); print '3nd: ', Dumper \$arg, \$n, \$count; sub Function { return ( 3 .. $arg ); } __END__ -- Just my 0.0002 million dollars worth, Shawn Prog

Re: function return

2010-04-30 Thread Akhthar Parvez K
On Thursday 29 Apr 2010, C.DeRykus wrote: > Um, that won't do what you think. The () just tosses all > the return arg's and $name remains undefined because > of the list context. > >   my($name) = () = Function1($arg);  # $name stays undef > > If $name were in scalar context though, you'd get a c

Re: function return

2010-04-30 Thread C.DeRykus
On Apr 29, 4:57 am, shawnhco...@gmail.com (Shawn H Corey) wrote: > Akhthar Parvez K wrote: > > Hi, > > > The following line stores the first return value by the function Function1 > > to the variable $name: > > > my ($name) = @_[0] = &Function1 ($arg); > > > but this one doesn't work: > > my ($nam

Re: function return

2010-04-29 Thread Shlomi Fish
On Thursday 29 Apr 2010 20:57:18 Akhthar Parvez K wrote: > On Thursday 29 Apr 2010, Shlomi Fish wrote: > > Just do: > > > > my ($name) = Function1 ($arg); > > > > This will evaluate Function1 in list context (instead of scalar or void > > context) and only get the first element. But the @_ of a f

Re: function return

2010-04-29 Thread Shlomi Fish
Hi all, On Thursday 29 Apr 2010 19:35:52 Shawn H Corey wrote: > Akhthar Parvez K wrote: > > On Thursday 29 Apr 2010, Shlomi Fish wrote: > >> Why are you assigning to variables inside @_? It's almost always a bad > >> idea. > >> > >> @_ is the function parameters' list. You should read the values

Re: function return

2010-04-29 Thread John W. Krahn
Akhthar Parvez K wrote: On Thursday 29 Apr 2010, Shlomi Fish wrote: Why are you assigning to variables inside @_? It's almost always a bad idea. @_ is the function parameters' list. You should read the values from there (using "my ($param1, $param2, $param3) = @_;" or "my $param1 = shift;" (sh

Re: function return

2010-04-29 Thread Akhthar Parvez K
On Thursday 29 Apr 2010, Shlomi Fish wrote: > Just do: > > my ($name) = Function1 ($arg); > > This will evaluate Function1 in list context (instead of scalar or void > context) and only get the first element. But the @_ of a function is not > affected by calls to other functions inside it. Cor

Re: function return

2010-04-29 Thread Shlomi Fish
On Thursday 29 Apr 2010 19:25:05 Akhthar Parvez K wrote: > On Thursday 29 Apr 2010, Shlomi Fish wrote: > > Why are you assigning to variables inside @_? It's almost always a bad > > idea. > > > > @_ is the function parameters' list. You should read the values from > > there (using "my ($param1, $p

Re: function return

2010-04-29 Thread Shawn H Corey
Akhthar Parvez K wrote: On Thursday 29 Apr 2010, Shlomi Fish wrote: Why are you assigning to variables inside @_? It's almost always a bad idea. @_ is the function parameters' list. You should read the values from there (using "my ($param1, $param2, $param3) = @_;" or "my $param1 = shift;" (sh

Re: function return

2010-04-29 Thread Akhthar Parvez K
On Thursday 29 Apr 2010, Shlomi Fish wrote: > Why are you assigning to variables inside @_? It's almost always a bad idea. > > @_ is the function parameters' list. You should read the values from there > (using "my ($param1, $param2, $param3) = @_;" or "my $param1 = shift;" (short > for "shift(@

Re: function return

2010-04-29 Thread Shlomi Fish
On Thursday 29 Apr 2010 14:31:38 Akhthar Parvez K wrote: > Hi, > > The following line stores the first return value by the function Function1 > to the variable $name: > > my ($name) = @_[0] = &Function1 ($arg); > Why are you assigning to variables inside @_? It's almost always a bad idea. @_ i

Re: function return

2010-04-29 Thread John W. Krahn
Akhthar Parvez K wrote: Hi, Hello, The following line stores the first return value by the function Function1 to the variable $name: my ($name) = @_[0] = &Function1 ($arg); The array slice @_[0] forces list context on the right side of the assignment but warns. $name in parentheses forc

Re: function return

2010-04-29 Thread Shawn H Corey
Akhthar Parvez K wrote: Hi, The following line stores the first return value by the function Function1 to the variable $name: my ($name) = @_[0] = &Function1 ($arg); but this one doesn't work: my ($name) = $_[0] = &Function1 ($arg); Eventhough I've no issues to use the first one as long as i

function return

2010-04-29 Thread Akhthar Parvez K
Hi, The following line stores the first return value by the function Function1 to the variable $name: my ($name) = @_[0] = &Function1 ($arg); but this one doesn't work: my ($name) = $_[0] = &Function1 ($arg); Eventhough I've no issues to use the first one as long as it works well for me, but

Re: anonymize function return

2006-04-04 Thread John W. Krahn
Vadim Kutchin wrote: > Hi! Hello, > I have some function, such as: > > === > sub func1 { > my (%rez); > > $rez{one} = 'one'; > $rez{two} = 'two'; > $rez{seven} = 'seven'; > > return %rez; > } > ===

Re: anonymize function return

2006-04-04 Thread Dr.Ruud
Vadim Kutchin schreef: > I have some function, such as: Missing: use strict; use warnings; > === > sub func1 { > my (%rez); > > $rez{one} = 'one'; > $rez{two} = 'two'; > $rez{seven} = 'seven'; > > return %rez; > } sub func1 {

Re: anonymize function return

2006-04-03 Thread Jeff Pang
>=== >sub func1 { >my (%rez); > >$rez{one} = 'one'; >$rez{two} = 'two'; >$rez{seven} = 'seven'; > >return %rez; >} >=== > >and I have such piece of code: > >=== >

anonymize function return

2006-04-03 Thread Vadim Kutchin
Hi! I have some function, such as: === sub func1 { my (%rez); $rez{one} = 'one'; $rez{two} = 'two'; $rez{seven} = 'seven'; return %rez; } === and I have such piece of code: