2013年1月20日日曜日

開発環境

『続・初めてのPerl 改訂版』(Randal L. Schwartz, brian d foy, Tom Phoenix 著、伊藤 直也田中 慎司吉川 英興 監訳、株式会社ロングテール/長尾 高弘 訳、オライリー・ジャパン、2006年、ISBN4-87311-305-9)の2章(中級者の基礎知識), 2.4(練習問題)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 map{"    $_\n"} grep { -s $_ < 1000} @ARGV;

入出力結果(Terminal)

$ ./sample.pl *
    Oogaboogoo
    __pycache__
    barney
    betty
    date.txt
    fred
    gilligan.info
    ginger.info
    hello_world.pl
    link_test
    ln.txt
    ln1.txt
    log
    lovey.info
    ls.err
    maryann.info
    monkeyman.info
    numbers
    perl_program1
    professor.info
    sample
    sample.pl
    sample.pl.bak
    sample.py
    sample_folder
    skipper.info
    some_file
    some_folder
    sortable_hash
    test.out
    test.txt
    test_folder
    test_link
    thurston.info
    tmp.txt
    tmp_folder
    untitled text 2.txt
$

pythonの場合。

sample.py

コード(BBEdit)

#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

import os, sys

argv = sys.argv[1:]
files = []
for file in argv:
    if os.path.getsize(file) < 1000:
        files.append(file)
a = map(lambda x: "    {0}\n".format(x), files)

for file in a:
    print(file, end="")

入出力結果(Terminal)

$ ./sample.py *
    Oogaboogoo
    __pycache__
    barney
    betty
    date.txt
    fred
    gilligan.info
    ginger.info
    hello_world.pl
    link_test
    ln.txt
    ln1.txt
    log
    lovey.info
    ls.err
    maryann.info
    monkeyman.info
    numbers
    perl_program1
    professor.info
    sample
    sample.pl
    sample.pl.bak
    sample.py
    sample_folder
    skipper.info
    some_file
    some_folder
    sortable_hash
    test.out
    test.txt
    test_folder
    test_link
    thurston.info
    tmp.txt
    tmp_folder
    untitled text 2.txt
$

0 コメント:

コメントを投稿