すぐわかるPerlでPerlを学ぶ(その1)

すぐわかるPerl (Software Technology)

すぐわかるPerl (Software Technology)


以前一度読み終えたのですが、改めて勉強します。
テストで使用する環境はレンタルサーバ(さくらインターネット)のFree BSD 6.1です。SSHでつないでテストします。

第一章

特筆すべき点はないのですが、とりあえず使用するperlのバージョンだけは確認しておきます。

itotto@www ~> perl -v

This is perl, v5.8.8 built for i386-freebsd-64int
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

itotto@www ~>


書籍が5.004くらいなので5.8.8とはちょっと離れています。ま、メジャーバージョンが一緒だからOK。
あとはperlの場所を覚えておこうということで配置場所を確認。

itotto@www ~> which perl
/usr/bin/perl
itotto@www ~>


アクセス権とか#!のあたりの話はさすがに今更なので読み飛ばし。そういえば#!って何ていう名前だっけ?と調べてみたけど分からず。とほほ。

第二章

演算子

基本的にはCと同じ演算子。とりあえず備忘程度に。

演算子 意味
+ 足す
- 引く
* かける
** 累乗
/ 割る
% 余り
+= 足した結果を代入
-= 引いた結果を代入
*= かけた結果を代入
**= 累乗した結果を代入
/= 割った結果を代入
%= 割った余りを代入
$x++ $xに1を加える($x++は足す前の結果) インクリメント
++$x $xに1を加える(++$xは足した後の結果) インクリメント
$x-- $xから1を引く($x--は引く前の結果) デクリメント
--$x $xから1を引く(--$xは引いた後の結果) デクリメント
perlを警告モードで起動

引数はまたあとでまとめまsぐあ、これは結構使いそうなのでピックアップ。

itotto@www > cat chk.pl
#!/usr/bin/perl -w

$hoge=10;

$hoge**=2;

print $hOge;
print "\n";


itotto@www > ./chk.pl
Name "main::hOge" used only once: possible typo at ./chk.pl line 7.
Use of uninitialized value in print at ./chk.pl line 7.

itotto@www >
文字列結合

文字列は . を使って結合します。+では結合できません。

// OK
$msg = "こんばんは\n"."これからもよろしく";

// NG(0になる)
$msg = "こんばんは\n"."これからもよろしく";
undefという値

初期化されて居ない変数の状態はundefという値として定義されています。



明日は3章からまとめます。