sub demonstration {
return {
demonstration_data => { demo_data => shift },
};
}
####
sub demonstration {
my $demonstration_data = { demo_data => shift };
return {
demonstration_data => $demonstration_data,
}, sub {
$demonstration_data = $_[0];
};
}
my ($data, $modifier) = demonstration('foo');
print Dumper $data;
$modifier->({ a => 1 });
print Dumper $data;
__END__
$VAR1 = {
'demonstration_data' => {
'demo_data' => 'foo'
}
};
$VAR1 = {
'demonstration_data' => {
'demo_data' => 'foo'
}
};
####
sub foo {
my $foo = shift;
return
$foo,
[ $foo ],
\$foo,
sub :lvalue { $foo }
;
}
my ($noref, $aref, $sref, $cref) = foo('foo');
my $dump = sub {
print
"\$noref: $noref\n",
"\$aref : $aref->[0]\n",
"\$sref : $$sref\n",
"\$cref : " . $cref->() . "\n\n";
};
$dump->(); $noref = 'bar'; # Changes the first value.
$dump->(); $aref->[0] = 'baz'; # Changes the second value.
$dump->(); $$sref = 'zip'; # Changes the two last values.
$dump->(); $cref->() = 'zap'; # Changes the two last values.
$dump->();
__END__
Long output, run it yourself.