デリファレンス

デリファレンスの優先順位とかセマンティクスとかがなんとなく解ってきました☆

use strict;
use warnings;
use Data::Dumper;
sub p { print Dumper shift }

my $hash_ref = {
	foo => "ABC",
	bar => "DEF",
};

my $array_ref = [
	"1111",
	"2222",
];


#-- Hash Ref.

p $hash_ref;

p $hash_ref->{foo};
p $$hash_ref{foo}; # これはあんまり使わない?

p %$hash_ref;

#-- Array Ref.

p $array_ref;

p $array_ref->[0];
p $$array_ref[0]; #

#-- もっと複雑なの

my $str = "hogehoge";
my $complex = {
	foo => [
		"111",
		"222",
		\$str,
	],
	bar => $hash_ref,
	baz => $array_ref,
};

p $complex;
p ${$complex->{foo}->[2]};
p $complex->{foo}->[0];
p $complex->{bar}->{foo};

# やじるしは省略したほうがいい?
p $complex->{foo}[0];
p $complex->{bar}{foo};

Perl はいろんなふうに書けるから、よけいにどうやって書いたらいいのかわからないかもヽ(  ̄д ̄;)ノ みんなどうやって書いてるのかなぁ (・_・。))

There is more than one way to do it. TIMTOWTDI っていうらしいですね。かっこいい! でも覚えられない (~ ~;)