in reply to Shortcut operator for $a->{'b'}=$b if $b;
I assume you mean $b is a long expression, so you'd rather avoid having it twice. If so, you could topicalize $b:
{ local $_ = $b; $a->{b} = $_ if defined $_; }
or (update)
$a->{b} = $_ foreach grep defined, $b;
or you could add everything then remove undefined values:
delete @$a{ grep { not defined $a->{$_} } keys %$a };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Shortcut operator for $a->{'b'}=$b if $b;
by rokadave (Sexton) on Sep 20, 2005 at 16:27 UTC | |
by ikegami (Patriarch) on Sep 20, 2005 at 16:32 UTC | |
by leriksen (Curate) on Sep 21, 2005 at 03:24 UTC | |
by ikegami (Patriarch) on Sep 21, 2005 at 05:28 UTC |
In Section
Seekers of Perl Wisdom