8.Perlの基礎 その18-2.Perl とは? 、 Perl プログラムの実行■ Perl とは?
Perl は、スクリプト言語と呼ばれるタイプのプログラム言語の一つです。
perl プログラムを確認
$ which perl # perl はどこ?
/usr/bin/perl $ $ perl -v # perl のバージョンは何? This is perl, v5.8.0 built for sun4-solaris Copyright 1987-2002, 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.com/, the Perl Home Page. ■ C言語との違い
Perl はC言語と似ていますが、違うところも多々あります。違いに気付かずに大きな間違いを犯す可能性もありますので注意しましょう。
■ Perl と C言語の比較
■ Hello World
kwrite で次のプログラムを "hello.pl" というファイル名で作成します。
$ kwrite hello.pl &
#! /usr/bin/perl
作成したプログラムを実行しましょう。カレントディレクトリで実行する場合はファイル名の前に "./" をつけます。
print "Hello World\n"; # "\n"(\n) は改行 exit;
$ ./hello.pl
実は、実行権限がありません。パーミッション・エラー ファイルのアクセス権限を確認しましょう。
$ ls -l
一番左の部分の表示を3文字ごとに区切って、「rwx」「r-x」「r--」と見ます。
-rw-rw-r-- 1 user group 42 OCT 20 2006 hello.pl
d、r、w、x、- の表記があり、それぞれの意味は以下の通り。
ユーザーに hello.pl に対する実行権限を与えるには、chmod コマンドによりパーミッションを変更する必要があります。
$ chmod u=rwx hello.pl # user はこのファイルを読み書き、実行できます。
$ ls -l -rwxrw-r-- 1 user group 42 OCT 20 2006 hello.pl 変更できたらもう一度、hello.pl を実行してみましょう。
$ ./hello.pl
Hello World |