----------------------------------------------------------------------------
連想配列(ハッシュ)

%gakki = ("guitar1"=>"John","bass"=>"Paul","guitar2"=>"George","drum"=>"Ringo");

または

%gakki = ("guitar1","John","bass","Paul","guitar2","George","drum","Ringo");

-----------------------------------------------------------------------------


オリジナル

$gakki{"guitar1"} $gakki{"bass"} $gakki{"guitar2"} $gakki{"drum"}
John Paul George Ringo


1.値を変更/代入する

$gakki {"guitar2"} = "Eric";

$gakki{"guitar1"} $gakki{"bass"} $gakki{"guitar2"} $gakki{"drum"}
John Paul Eric Ringo


2.keys(すべてのキー値を取り出す)

@instrument_k = keys %gakki;

$instrument_k = keys %gakki;

@instrument_k → drum bass guitar1 guitar2

$instrument_k → 4



3.values(すべての値を取り出す)

@members_v = values %gakki ;

@members_v → Ringo Paul John George



4.each(キーと値を取り出す)

($key,$value) = each %gakki;

$key → drum $value → Ringo

$key → bass $value → Paul

$key → guitar1 $value → John

$key → guitar2 $value → George



5.delete(要素を取り除く)

delete $gakki {"guitar1"} ;

$gakki{"bass"} $gakki{"guitar2"} $gakki{"drum"}
Paul George Ringo


@instrument_d → drum bass guitar2

$instrument_d → 3