live4tech has asked for the wisdom of the Perl Monks concerning the following question:
I recently came upon the following line of code:
$FH = $OUTFH{$name} ||= IO::File->new(">g:\\perl_scripts\\$name.log") +or die $!;
I have looked for the ||= operator and found it only in a table in perlop. There is no description of it or examples using it. I have not found it anywhere else.
From the context of the above code line and through some testing I found that the line works like this: $FH will be set to $OUTFH{$name} if $OUTFH{$name} is defined. If $OUTFH{$name} is undefined, $FH is set to the IO::File reference.
Is this the same as //? This is really poorly documented...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: ||= (poorly documented?)
by frozenwithjoy (Priest) on Jul 09, 2012 at 05:55 UTC | |
Re: ||= (poorly documented?)
by kcott (Archbishop) on Jul 09, 2012 at 06:02 UTC | |
Re: ||= (poorly documented?)
by tobyink (Canon) on Jul 09, 2012 at 06:54 UTC | |
Re: ||= (poorly documented?)
by Marshall (Canon) on Jul 09, 2012 at 07:36 UTC | |
by dsheroh (Monsignor) on Jul 09, 2012 at 09:23 UTC | |
by Marshall (Canon) on Jul 09, 2012 at 09:37 UTC | |
by dsheroh (Monsignor) on Jul 09, 2012 at 12:16 UTC | |
Re: ||= (poorly documented?)
by DrHyde (Prior) on Jul 09, 2012 at 09:55 UTC | |
Re: ||= (poorly documented?)
by Anonymous Monk on Jul 09, 2012 at 06:21 UTC | |
by frozenwithjoy (Priest) on Jul 09, 2012 at 06:31 UTC | |
by dsheroh (Monsignor) on Jul 09, 2012 at 09:15 UTC | |
by frozenwithjoy (Priest) on Jul 09, 2012 at 09:46 UTC | |
by Anonymous Monk on Jul 09, 2012 at 14:56 UTC | |
by frozenwithjoy (Priest) on Jul 09, 2012 at 15:12 UTC | |
by Anonymous Monk on Jul 09, 2012 at 22:10 UTC | |
Re: ||= (poorly documented?)
by Anonymous Monk on Jul 09, 2012 at 06:36 UTC | |
by frozenwithjoy (Priest) on Jul 09, 2012 at 06:47 UTC |
Back to
Seekers of Perl Wisdom