in reply to Re: I can't see why this shorthand doesn't behave like the verbose form
in thread I can't see why this shorthand doesn't behave like the verbose form

Here is a demonstration of it working, and some alternatives :)

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use JSON::XS; my $ref = { foo => q{[1,2,3]} }; for my $key( qw/ bar foo /) { { my $foo; if( $ref->{$key} ){ $foo = decode_json( $ref->{$key} ); } else { $foo = []; } dd $foo; } { my $foo = []; if( $ref->{$key} ){ $foo = decode_json( $ref->{$key} ); } dd $foo; } { my $foo = $ref->{$key} ? decode_json( $ref->{$key} ) : []; dd $foo; } { my $foo = eval { decode_json( $ref->{$key} ) } || []; dd $foo; } } __END__ [] [] [] [] [1, 2, 3] [1, 2, 3] [1, 2, 3] [1, 2, 3]
  • Comment on Re^2: I can't see why this shorthand doesn't behave like the verbose form
  • Download Code