Perlの$と@で指定した配列の操作についてサンプルコードを記します。
@ary1 = (1,2,3); $ary2 = [1,2,3];
の違いです。
htmlinsert(): The given local file does not exist or is not readable.
$ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for i686-linux-gnu-thread-multi-64int (with 57 registered patches, see perl -V for more detail) <snip>
$ lsb_release -d Description: Ubuntu 12.04.4 LTS
配列の$変数と@変数の違いについてサンプルコードを添えて以下に記します。
use strict; use warnings;
my $a1 = ["a","b","c"]; my @a2 = (1,2,3);
print '-- $a1 --'. "\n"; print "$a1->[0]\n"; print "$a1->[1]\n"; print "$a1->[2]\n";
print '-- @a2 --'. "\n"; print "$a2[0]\n"; print "$a2[1]\n"; print "$a2[2]\n";
上記のサンプルコードでは、無名配列のリファレンスである$a1と配列である@a2に値を設定しprintで内容を表示しています。
サンプルコードを見るとわかるように
無名配列のリファレンスである$a1の場合は
$a1->[要素番号]
で内容を表示することができます。
配列である@a2の場合は
$a2[要素番号]
で内容を表示することができます。
以上、無名配列のリファレンスと配列の要素操作についての記事でした。