From: "Dr.Ruud" <[EMAIL PROTECTED]> > Rob Dixon schreef: > > Dr.Ruud: > >> John W . Krahn: > > >>> /Powerball:/ and my @numbers = /\d+/g; > >> > >> I wouldn't use such a conditional "my". > > > > There is no conditional 'my': it is a de[c]laration. > > I call it a conditional "my". A "my" can be just a declaration, or a > declaration and an initialisation. In this case only the initialisation > is conditional. > > A "my" in a condition has special behaviour if the condition is constant > false: "0 and my $var;" creates a static $var. > > As I wrote: *I* wouldn't use *such* a conditional "my". I put the > declaration on its own line, just before the conditional initialisation. > > I sometimes use a conditional my if I want the static behaviour, but not > in production code. Perl 5.10 has "static".
Perl 5.x has { my $static; sub foo { $static++; ... } } which even lets you create variables that are shared by several subroutines. I do understand you might want to use my() like this: open my $FH, '>', $filename or die $^E; or if (my $foo = foo($x, $y, $z) and my $bar = bar(1,2,3)) { and use $foo and $bar here } but I'd definitely never ever do condition and my $x = blah(); and if 0 and my $x; creates a static $x I call it a bug. Jend ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/