開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Perl
『初めてのPerl 第6版』(Randal L. Schwartz, Tom Phoenix, brian d foy 共著、近藤 嘉雪 訳、オライリー・ジャパン、2012年、ISBN978-4-87311-567-2)の5章(入出力)、5.13(練習問題)1を解いてみる。
その他参考書籍
1.
コード(BBEdit)
sample.pl
#!/usr/bin/env perl use strict; use warnings; use utf8; use 5.016; binmode STDOUT, ':utf8'; binmode STDIN, ':utf8'; print reverse <>;
入出力結果(Terminal)
$ cat fred barney betty fred 1 fred 2 fred 3 fred 4 barney 1 barney 2 barney 3 barney 4 barney 5 (barney fife?) barney 6 betty 1 betty 2 betty 3 betty 4 betty 5 $ ./sample.pl fred barney betty betty 5 betty 4 betty 3 betty 2 betty 1 barney 6 barney 5 (barney fife?) barney 4 barney 3 barney 2 barney 1 fred 4 fred 3 fred 2 fred 1 $
pythonの場合。
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- import sys files = sys.argv[1:] files.reverse() for file in files: with open(file) as f: lines = f.readlines() lines.reverse() for line in lines: print(line, end="")
入出力結果(Terminal)
$ ./sample.py fred barney betty betty 5 betty 4 betty 3 betty 2 betty 1 barney 6 barney 5 (barney fife?) barney 4 barney 3 barney 2 barney 1 fred 4 fred 3 fred 2 fred 1 $
0 コメント:
コメントを投稿