開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Perl
『初めてのPerl 第5版』(Randal L. Schwartz, Tom Phoenix, brian d foy 共著、近藤 嘉雪 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-427-9) の5章(入出力), 5.12(練習問題)3を解いてみる。
3.
やり方の1つ。(「やり方は何通りもある」(TIMTOWTDI(There Is More Than One Way To Do It.)))
コード(TextWrangler)
#!/usr/bin/env perl use strict; use warnings; print "カラムの幅を入力: "; chomp(my $cols = <STDIN>); print "文字列を入力\n"; chomp(my @lines = <STDIN>); print "1234567890" x ($cols / 10 + 1) . "\n"; for(@lines){ printf "%${cols}s\n", $_; }
入出力結果(Terminal)
$ perl sample.pl カラムの幅を入力: 30 文字列を入力 hello good-bye 1234567890123456789012345678901234567890 hello good-bye $
0 コメント:
コメントを投稿