[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl-beginners
Subject:    deprecated idiom to simulate state variables
From:       Luca Ferrari <fluca1978 () infinito ! it>
Date:       2017-01-10 8:04:00
Message-ID: CAKoxK+49MOhXR=2Koy_44x-7k=8KSUDN+g1-iPx6=vDfSrhfzQ () mail ! gmail ! com
[Download RAW message or body]

Hi all,
I guess it was in Modern Perl that I saw this deprecated idiom to
simulate state <http://perldoc.perl.org/functions/state.html>
variables:

sub foo{
   my $initialized_once = 1 if 0;
  ...
}

Now, why is that working and initializing the variable the first time?
I mean, each time such row is evaluated the condition is 0 = false, so
the variable should not be initialized never.
What am I missing?

Thanks,
Luca

-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic