「Perl」配列の要素へのアクセスサンプル

書式
1.配列の宣言
@配列名 = (要素1,要素2,xxx)
2.配列の要素へのアクセス
「$ + 配列名 + インデックス」で配列の要素を取得します。

使用例

#!/usr/bin/perl
 
@hits = (25, 33, 44);             
@names = ("google", "arkgame", "yahoo");
 
print "\$hits[0] = $hits[0]\n";
print "\$hits[1] = $hits[1]\n";
print "\$hits[2] = $hits[2]\n";
print "\$names[0] = $names[0]\n";
print "\$names[1] = $names[1]\n";
print "\$names[2] = $names[2]\n";

実行結果

$hits[0] = 25
$hits[1] = 33
$hits[2] = 44
$names[0] = google
$names[1] = arkgame
$names[2] = yahoo

 

Perl

Posted by arkgame