Re: state vs my

2004-12-10 Thread Michele Dondi
On Fri, 3 Dec 2004, Brent 'Dax' Royal-Gordon wrote: Larry Wall [EMAIL PROTECTED] wrote: So optimizing to a state variable won't necessarily help your loop overhead, but it could help your subroutine overhead, at least in Perl 5, if Perl 5 had state variables. Best you can do in Perl 5 is an our

Re: state vs my

2004-12-10 Thread Alexey Trofimenko
On Sat, 4 Dec 2004 22:03:19 -0800, Larry Wall [EMAIL PROTECTED] wrote: On Sun, Dec 05, 2004 at 02:15:51AM +0300, Alexey Trofimenko wrote: : oh! that it. I've found example which could make it clear to me : : sub test { : return sub { : for 1..3 { :state $var = 1; :print

Re: state vs my

2004-12-04 Thread Larry Wall
On Fri, Dec 03, 2004 at 11:36:02PM -0800, Brent 'Dax' Royal-Gordon wrote: : Larry Wall [EMAIL PROTECTED] wrote: : So optimizing to a state variable won't necessarily help your loop : overhead, but it could help your subroutine overhead, at least in Perl : 5, if Perl 5 had state variables. Best

Re: state vs my

2004-12-04 Thread Alexey Trofimenko
On Fri, 3 Dec 2004 21:25:39 -0800, Larry Wall [EMAIL PROTECTED] wrote: On Sat, Dec 04, 2004 at 06:31:35AM +0300, Alexey Trofimenko wrote: : : for 1..10_000_000 { : my ($a,$b,$c) = ... : ... : } : : vs. : : for 1..10_000_000 { : state ($a,$b,$c) = ... : ... : } : :

Re: state vs my

2004-12-04 Thread Larry Wall
On Sat, Dec 04, 2004 at 08:03:45PM +0300, Alexey Trofimenko wrote: : P.S. : btw, what about : : my @rray; : # i'm starting to like that sigil is a part of name idea :) Too cute. But what about %ash and unction? Or is it ubroutine? losure? : for 1..10 { : { :push @rray, \(

Re: state vs my

2004-12-04 Thread Alexey Trofimenko
On Sat, 4 Dec 2004 11:33:10 -0800, Larry Wall [EMAIL PROTECTED] wrote: On Sat, Dec 04, 2004 at 08:03:45PM +0300, Alexey Trofimenko wrote: : P.S. : btw, what about : : my @rray; : # i'm starting to like that sigil is a part of name idea :) : for 1..10 { : { :push @rray, \( state

Re: state vs my

2004-12-04 Thread Larry Wall
On Sun, Dec 05, 2004 at 02:15:51AM +0300, Alexey Trofimenko wrote: : I thought, its primary use is for closures: : : sub test { : my $a=10; : return sub { $a++ } : } : : vs : sub test { : return sub {state $a=10; $a++ } : } : : $func1 = test; : $func2 = test; : : would

state vs my

2004-12-03 Thread Alexey Trofimenko
for 1..10_000_000 { my ($a,$b,$c) = ... ... } vs. for 1..10_000_000 { state ($a,$b,$c) = ... ... } latter looks like it would run faster, because no reallocation envolved here. I've read an advice somewhat like that in Ruby docs, tried it on perl5, and it really

Re: state vs my

2004-12-03 Thread Larry Wall
On Sat, Dec 04, 2004 at 06:31:35AM +0300, Alexey Trofimenko wrote: : : for 1..10_000_000 { : my ($a,$b,$c) = ... : ... : } : : vs. : : for 1..10_000_000 { : state ($a,$b,$c) = ... : ... : } : : latter looks like it would run faster, because no reallocation envolved

Re: state vs my

2004-12-03 Thread Brent 'Dax' Royal-Gordon
Larry Wall [EMAIL PROTECTED] wrote: So optimizing to a state variable won't necessarily help your loop overhead, but it could help your subroutine overhead, at least in Perl 5, if Perl 5 had state variables. Best you can do in Perl 5 is an our variable with an obscure name. my $x if 0;