# ハッシュへの参照のテスト
use strict;
use warnings;
use utf8;
use Encode;
binmode( STDIN, ':encoding(CP932)' );
binmode( STDOUT, ':encoding(CP932)' );
binmode( STDERR, ':encoding(CP932)' );
my $refHash = {};
p();
$refHash->{'distance'} = {};
p();
$refHash = func( $refHash );
p();
$refHash->{'distance'}{'value'} = 5;
p();
$refHash = func( $refHash );
p();
sub p
{
my $dist = $refHash->{'distance'} && $refHash->{'distance'}{'value'} || -1;
printf( "%d\n", $dist );
}
sub func
{
my( $r ) = @_;
if (
ref( $r ) eq 'HASH'
&& ref( $r->{'distance'} ) eq 'HASH'
&& $r->{'distance'}{'value'}
){
$r->{'distance'}{'value'} *= 2;
}
return $r;
}
# EOF
-1
-1
-1
5
10
This version of the page was edited by TakeAsh at 2018-09-01 01:15:27. View the most recent version.