x演算子を使うと、文字列やリストなどの処理を繰り返すことができる。
実行すると、
$ vi x_operator.pl $ perl x_operator.pl ABCABCABC 10 20 10 20 $
確かに繰り返している。
Sample/perl/x_operator/x_operator/src/x_operator at master · bg1bgst333/Sample · GitHub
x演算子を使うと、文字列やリストなどの処理を繰り返すことができる。
実行すると、
$ vi x_operator.pl $ perl x_operator.pl ABCABCABC 10 20 10 20 $
確かに繰り返している。
Sample/perl/x_operator/x_operator/src/x_operator at master · bg1bgst333/Sample · GitHub
**で冪乗を計算できる。
実行すると、
$ vi exponentiation_operator.pl $ perl exponentiation_operator.pl $y1 = 8 $y2 = 625 $y3 = 49 $
冪乗が計算できてる。
Perlは、変数名などのシンボルが同じでも、頭の記号で、変数だったり、配列だったり、ハッシュだったりする。
型グロブは、このシンボルテーブルのエントリーを表現する。
*をつけて型グロブを取得できる。
型グロブに型グロブを代入すると、代入先に代入元の情報が引き継がれ、エイリアスとなる。
$ vi type_glob.pl $ perl type_glob.pl ABCDE (1,2,3) {value1,value2} *main::type_glob ABCDE (1,2,3) {value1,value2} *main::type_glob $
表面上の変数名が変わっても、型グロブにおけるシンボル名は変わってない。
Sample/perl/type_glob/type_glob/src/type_glob at master · bg1bgst333/Sample · GitHub
シンボリックリファレンスは、非常に不思議な機能である。
The Perl5 Manual - シンボリックリファレンス
シンボリックリファレンス
単なる文字列の代入が、その文字列の名の付いた変数へのリファレンスの代入にもなるという2つの意味を持つ。
どちらを出力しても、
$ vi reference.pl $ perl reference.pl 123 variable $
どちらの機能も維持している。
Sample/perl/reference/symbolic_reference/src/reference at master · bg1bgst333/Sample · GitHub
ハッシュのリファレンスをネストしていって、構造体を作ることができる。
foreachで構造体のメンバを比較的簡単に参照できる。
$ vi hash.pl $ perl hash.pl 1 Taro 20 Tokyo 2 Jiro 18 Osaka 3 Saburo 16 Nagoya $
このように各プロファイルを出力できる。
Sample/perl/hash/struct/src/hash at master · bg1bgst333/Sample · GitHub
配列のリファレンスをネストしていくと、多次元配列を作ることができる。
添字と添字の間のアロー演算子は省略できるので、より多次元配列っぽさがある。
$ vi array.pl $ perl array.pl 1 5 9 1 5 9 $
指定した要素を取り出せている。
Sample/perl/array/multi_dimensional_array/src/array at master · bg1bgst333/Sample · GitHub
C言語のポインタと同じく、配列などのリファレンスから要素の値を参照する場合はアロー演算子が使える。
添字の[]の前や、{}の前に->を置くことができる。
$ vi arrow_operator.pl $ perl arrow_operator.pl 3 3 value2 value2 $
このように値を取得できる。
Sample/perl/arrow_operator/arrow_operator/src/arrow_operator at master · bg1bgst333/Sample · GitHub