in reply to Re^2: Arrow Operator Question
in thread Arrow Operator Question
This is dangerous: the nature of my $var = ... if ... is predictable but very noninuitive (it acts something like a state variable). It has long been regarded as a bug that perl core would dearly love to fix, but cannot due to back-compat.
I recommend always either splitting out the declaration from the assignment:
my $f; $f = $h->{b}{c}{d} if exists($h->{b}{c}) and exists($h->{b}{c}{d});
.. or using state explicitly when that's what you actually intend:
use feature 'state'; # 'use 5.10' or later also gives this automatica +lly state $f = $h->{b}{c}{d} if exists($h->{b}{c}) and exists($h->{b}{c}{d +});
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Arrow Operator Question
by BillKSmith (Monsignor) on Mar 28, 2023 at 18:07 UTC |