« 「すぐわかるPerl」2.1 プログラムのリサイクル | トップページ | MCAS Word/Excel2007完全マスター2 模擬問題集 »

2007年9月30日 (日)

「すぐわかるPerl」2.2 Printで遊んでみよう

Microsoft Virtial PC2007にfedora core6をいれて、そこでperlを動かしてます。
こちらの方がviとかを使える(学べる)分、良いかもしれないですね。

printで出力するとき、文字列のみであれば()は不要となる。

[sironekotoro@localhost perl-study]$ cat flashy
#! /usr/bin/perl
# flashy -- 派手な挨拶のプログラム
print "************************************************\n";
print "*** hello! Welcome! to the perl World!(^-^) ****\n";
print "************************************************\n";

[sironekotoro@localhost perl-study]$ perl flashy
************************************************
*** hello! Welcome! to the perl World!(^-^) ****
************************************************

一個のprint命令で出力してみた場合。冗長だけど、結果は同じ。

[sironekotoro@localhost perl-study]$ cat flashy-long
#! /usr/bin/perl
# flashy -- 派手な挨拶のプログラム
print "************************************************\n*** hello! Welcome! to the perl World!(^-^) ****\n************************************************\n";

[sironekotoro@localhost perl-study]$ perl flashy-long
************************************************
*** hello! Welcome! to the perl World!(^-^) ****
************************************************

改行は\nという特殊文字によって行われる。
\tはタブの挿入。

[sironekotoro@localhost perl-study]$ perl
print "L\n\tL\n\t\tL\n\t\t\tL\n";
L
        L
                L
                        L

print文で分けても同じ表現になる。

[sironekotoro@localhost perl-study]$ perl
print "L\n";
print "\tL\n";
print "\t\tL\n";
print "\t\t\tL\n";
L
        L
                L
                        L

|

« 「すぐわかるPerl」2.1 プログラムのリサイクル | トップページ | MCAS Word/Excel2007完全マスター2 模擬問題集 »

Perl」カテゴリの記事

コメント

コメントを書く



(ウェブ上には掲載しません)


コメントは記事投稿者が公開するまで表示されません。



トラックバック

この記事のトラックバックURL:
http://app.cocolog-nifty.com/t/trackback/214806/16616906

この記事へのトラックバック一覧です: 「すぐわかるPerl」2.2 Printで遊んでみよう:

« 「すぐわかるPerl」2.1 プログラムのリサイクル | トップページ | MCAS Word/Excel2007完全マスター2 模擬問題集 »