ããªãã¡ã¬ã³ã¹
ããªãã¡ã¬ã³ã¹ã¨ã¯リファレンスãä½æããã®ã¨å対ã®æä½ã§ããªãã¡ã¬ã³ã¹ããå®ä½ãåãåºããã¨ãã§ãã¾ãã
é åã®ãªãã¡ã¬ã³ã¹ãããªãã¡ã¬ã³ã¹
配列のリファレンスãããªãã¡ã¬ã³ã¹ããã«ã¯ã@{}ãã使ç¨ãã¾ãã
my @array = @{$array_ref};
æ°ãã配列ãä½ãããããã§ã¯ãªããå®ä½ãåãåºããã¦ããã¨ãããã¨ãæèãã¦ãã ããã
ã@{}ãã®å å´ãåç´ãª変数ã®å ´åã¯ã{}ããçç¥ãããã¨ãã§ãã¾ãã
my @array = @$array_ref;
é åã®ãªãã¡ã¬ã³ã¹ãããªãã¡ã¬ã³ã¹ãããµã³ãã«ããã°ã©ã ã§ãã
# é åã®ãªãã¡ã¬ã³ã¹ my $nums_ref = [1, 2, 3]; # ããªãã¡ã¬ã³ã¹ my @nums = @$nums_ref;
Perlã®é åæä½ãè¡ã標準関数ã¯ãé åã®ãªãã¡ã¬ã³ã¹ã§ã¯ãªããé åã渡ãå¿ è¦ãããã¾ãããã®ãããªå ´åã¯ãããªãã¡ã¬ã³ã¹ãã¦ãé¢æ°ã«æ¸¡ãã¦ãã ããã
my $nums = [1, 2, 3]; my $num = shift @$nums;
ããã·ã¥ã®ãªãã¡ã¬ã³ã¹ãããªãã¡ã¬ã³ã¹
ハッシュのリファレンスã®ããªãã¡ã¬ã³ã¹ãè¡ãã«ã¯ã%{}ãã使ç¨ãã¾ãã
my %hash = %{$hash_ref};
æ°ããハッシュãä½ãããããã§ã¯ãªããå®ä½ãåãåºããã¦ããã¨ãããã¨ãæèãã¦ãã ããã
ã%{}ãã®å å´ãåç´ãªå¤æ°ã®å ´åã¯ã{}ããçç¥ãããã¨ãã§ãã¾ãã
my %hash = %$hash_ref;
ããã·ã¥ã®ãªãã¡ã¬ã³ã¹ãããªãã¡ã¬ã³ã¹ãããµã³ãã«ããã°ã©ã ã§ãã
# ããã·ã¥ã®ãªãã¡ã¬ã³ã¹ my $score_ref = {math => 19, english => 89}; # ããªãã¡ã¬ã³ã¹ my %score = %$score_ref;
Perlã®ããã·ã¥æä½ãè¡ãæ¨æºé¢æ°ã¯ãããã·ã¥ã®ãªãã¡ã¬ã³ã¹ã§ã¯ãªããããã·ã¥ã渡ãå¿ è¦ãããã¾ãããã®ãããªå ´åã¯ãããªãã¡ã¬ã³ã¹ãã¦ãé¢æ°ã«æ¸¡ãã¦ãã ããã
my $score = {math => 89, english => 45}; my @keys = keys %$score;
ã¹ã«ã©å¤æ°ã®ãªãã¡ã¬ã³ã¹ãããªãã¡ã¬ã³ã¹
スカラ変数ã®ãªãã¡ã¬ã³ã¹ã®ããªãã¡ã¬ã³ã¹ãè¡ãã«ã¯ã${}ãã使ç¨ãã¾ãã
my $scalar = ${$scalar_ref};
ã${}ãã®å å´ãåç´ãªå¤æ°ã®å ´åã¯ã{}ããçç¥ãããã¨ãã§ãã¾ãã
my $scalar = $$scalar_ref;
ã¹ã«ã©ã®ãªãã¡ã¬ã³ã¹ãããªãã¡ã¬ã³ã¹ãããµã³ãã«ããã°ã©ã ã§ãã
# ã¹ã«ã©ã®ãªãã¡ã¬ã³ã¹ my $string1 = "Hello"; my $string_ref = \$string; # ããªãã¡ã¬ã³ã¹ my $string2 = $$string_ref;
ä»ã®ãªãã¡ã¬ã³ã¹ã®ããªãã¡ã¬ã³ã¹ã¯ã§ããã®?
サブルーチンのリファレンスã¨正規表現のリファレンスã¯ãããªãã¡ã¬ã³ã¹ãããã¨ãã§ãã¾ããã