Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Arrow Operator Question

by BillKSmith (Monsignor)
on Mar 28, 2023 at 18:02 UTC ( [id://11151299] : note . print w/replies, xml ) Need Help??


in reply to Re^3: Arrow Operator Question
in thread Arrow Operator Question

sectokia only showed us the fail case. I assume that his code worked as he expected in the pass case. I should have demonstrated that my code produced the same result in that case.
use strict; use warnings; use Data::Dumper; use Test::More tests=>2; my $h = { b => { c => { d => 'value' } } }; my $g = $h->{b}{c}{d} if exists($h->{b}{c}) and exists($h->{b}{c}{d}); my $f = $h->{b}{c}{d}//undef; # Original Code is( $g, $f, $f ); is_deeply( $h, { b => { c => { d => 'value' } } }, 'no change' );

The difference between your various f's is not merely one of style, but one of requirements (which we really do not know).

Bill