in reply to I can't see why this shorthand doesn't behave like the verbose form
#! perl use Data::Dumper; use JSON::XS; my $asset = { ## rename this var to something else to test the 'undefined' c +ase related_files => '{ "firstName": "John", "lastName" : "Smith", "age" : 25, "address" : { "streetAddress": "21 2nd Street", "city" : "New York", "state" : "NY", "postalCode" : "10021" }, "phoneNumber": [ { "type" : "home", "number": "212 555-1234" }, { "type" : "fax", "number": "646 555-4567" } ] }' }; my $ref; if($asset->{related_files}){ $ref = decode_json($asset->{related_files}); }else{ $ref = []; } print Dumper($ref); ## simpler shorthand-code doesn't work, why? my $ref = $asset->{related_files} ? decode_json($asset->{related_files +}) : []; print Dumper($ref);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I can't see why this shorthand doesn't behave like the verbose form
by tobyink (Canon) on Mar 25, 2012 at 14:52 UTC | |
|
Re^2: I can't see why this shorthand doesn't behave like the verbose form
by Anonymous Monk on Mar 25, 2012 at 14:26 UTC |