開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc., Emacs(Text Editor)
- プログラミング言語: Perl
『初めてのPerl 第6版』(Randal L. Schwartz, Tom Phoenix, brian d foy 共著、近藤 嘉雪 訳、オライリー・ジャパン、2012年、ISBN978-4-87311-567-2)の17章(上級テクニック)の17.6(練習問題)3を解いてみる。
その他参考書籍
3.
コード(BBEdit)
sample.pl
#!/usr/bin/env perl use strict; use warnings; use 5.016; use utf8; binmode STDOUT, ':utf8'; binmode STDIN, ':utf8'; binmode STDERR, ':utf8'; for my $file (glob ".* *") { my ($atime, $mtime) = map { my ($year, $month, $day) = (localtime $_)[5, 4, 3]; $year += 1900; $month += 1; sprintf "%4d-%02d-%02d", $year, $month, $day; } (stat $file)[8, 9]; printf "%-25s%15s%15s\n", $file, $atime, $mtime; }
入出力結果(Terminal)
$ ./sample.pl . 2013-09-02 2013-08-29 .. 2013-08-28 2013-08-27 .DS_Store 2013-09-02 2013-08-17 .out 2012-12-20 2012-03-16 __pycache__ 2013-08-11 2013-09-01 barney 2013-07-13 2001-06-10 betty 2013-07-13 2001-06-10 coconet.dat 2013-03-20 2011-10-24 coconet_total.dat 2013-01-27 2013-01-27 coconet_total_2.dat 2013-01-27 2013-01-27 date.log 2013-01-30 2013-01-30 date.txt 2013-08-31 2012-04-24 distribute-0.6.34.tar.gz 2013-01-23 2013-01-23 fred 2013-07-13 2001-06-10 gilligan.info 2013-01-31 2013-01-31 Gilligan: 2013-01-31 2013-01-31 ginger.info 2013-01-31 2013-01-31 Ginger: 2013-01-31 2013-01-31 hello_world.pl 2013-03-30 2013-03-23 html 2013-06-30 2013-06-30 link_test 2013-08-31 2012-03-18 ln.txt 2013-08-31 2013-01-01 ln1.txt 2013-08-31 2013-01-01 log 2012-12-20 2012-10-26 log_file.txt 2013-08-31 2011-07-28 lovey.info 2013-01-31 2013-01-31 Lovey: 2013-01-31 2013-01-31 ls.out 2013-08-29 2013-08-29 maryann.info 2013-01-31 2013-01-31 MaryAnn: 2013-01-31 2013-01-31 monkeyman.info 2013-01-31 2013-01-31 MonkeyMan: 2013-01-31 2013-01-31 numbers 2012-12-20 2001-06-10 Oogaboogoo 2013-08-11 2013-02-06 perl_kamimura_blog 2013-03-10 2012-12-20 perl_kamimura_blog.html 2013-09-01 2013-09-01 perl_program1 2012-12-20 2012-03-19 professor.info 2013-01-31 2013-01-31 Professor: 2013-01-31 2013-01-31 result 2012-12-20 2012-07-18 sample 2013-08-31 2012-06-26 sample.pl 2013-09-02 2013-09-02 sample.py 2013-09-02 2013-09-01 sample.txt 2013-08-31 2013-07-17 sample_folder 2013-08-31 2012-06-25 sample_text 2013-01-28 2001-06-10 skipper.info 2013-01-31 2013-01-31 Skipper: 2013-01-31 2013-01-31 some_file 2013-03-30 2013-03-30 some_folder 2013-08-11 2013-01-02 sortable_hash 2012-12-20 2001-06-10 standings.db 2013-02-10 2013-02-10 test.out 2012-12-20 2012-12-15 test.py 2013-04-11 2013-03-24 test.txt 2013-08-31 2012-03-18 test.txt.out 2013-03-23 2013-03-23 test_folder 2013-08-11 2012-04-30 test_link 2013-08-31 2012-03-18 thurston.info 2013-01-31 2013-01-31 Thurston: 2013-01-31 2013-01-31 tmp.txt 2013-08-31 2013-08-16 tmp1.txt 2013-08-31 2013-08-16 tmp2.txt 2013-08-31 2013-08-16 total_bytes.dat 2012-10-24 2012-10-24 untitled text 2.txt 2013-08-31 2012-11-05 $
ちなみにpython3.3の場合。
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3 ## Copyright (C) 2013 by kamimura #-*- coding: utf-8 -*- import glob, os, time for file in glob.glob('*'): atime, mtime = map( lambda x: "{0:4d}-{1:02d}-{2:02d}".format( time.localtime(x)[0], time.localtime(x)[1], time.localtime(x)[2]), os.stat(file)[7:9]) print("{0:25s}{1:15s}{2:15s}".format(file, atime, mtime))
入出力結果(Terminal)
$ ./sample.py __pycache__ 2013-08-11 2013-09-01 barney 2013-07-13 2001-06-10 betty 2013-07-13 2001-06-10 coconet.dat 2013-03-20 2011-10-24 coconet_total.dat 2013-01-27 2013-01-27 coconet_total_2.dat 2013-01-27 2013-01-27 date.log 2013-01-30 2013-01-30 date.txt 2013-08-31 2012-04-24 distribute-0.6.34.tar.gz 2013-01-23 2013-01-23 fred 2013-07-13 2001-06-10 gilligan.info 2013-01-31 2013-01-31 Gilligan: 2013-01-31 2013-01-31 ginger.info 2013-01-31 2013-01-31 Ginger: 2013-01-31 2013-01-31 hello_world.pl 2013-03-30 2013-03-23 html 2013-06-30 2013-06-30 link_test 2013-08-31 2012-03-18 ln.txt 2013-08-31 2013-01-01 ln1.txt 2013-08-31 2013-01-01 log 2012-12-20 2012-10-26 log_file.txt 2013-08-31 2011-07-28 lovey.info 2013-01-31 2013-01-31 Lovey: 2013-01-31 2013-01-31 ls.out 2013-08-29 2013-08-29 maryann.info 2013-01-31 2013-01-31 MaryAnn: 2013-01-31 2013-01-31 monkeyman.info 2013-01-31 2013-01-31 MonkeyMan: 2013-01-31 2013-01-31 numbers 2012-12-20 2001-06-10 Oogaboogoo 2013-08-11 2013-02-06 perl_kamimura_blog 2013-03-10 2012-12-20 perl_kamimura_blog.html 2013-09-02 2013-09-02 perl_program1 2012-12-20 2012-03-19 professor.info 2013-01-31 2013-01-31 Professor: 2013-01-31 2013-01-31 result 2012-12-20 2012-07-18 sample 2013-08-31 2012-06-26 sample.pl 2013-09-02 2013-09-02 sample.py 2013-09-02 2013-09-02 sample.txt 2013-08-31 2013-07-17 sample_folder 2013-08-31 2012-06-25 sample_text 2013-01-28 2001-06-10 skipper.info 2013-01-31 2013-01-31 Skipper: 2013-01-31 2013-01-31 some_file 2013-03-30 2013-03-30 some_folder 2013-08-11 2013-01-02 sortable_hash 2012-12-20 2001-06-10 standings.db 2013-02-10 2013-02-10 test.out 2012-12-20 2012-12-15 test.py 2013-04-11 2013-03-24 test.txt 2013-08-31 2012-03-18 test.txt.out 2013-03-23 2013-03-23 test_folder 2013-08-11 2012-04-30 test_link 2013-08-31 2012-03-18 thurston.info 2013-01-31 2013-01-31 Thurston: 2013-01-31 2013-01-31 tmp.txt 2013-08-31 2013-08-16 tmp1.txt 2013-08-31 2013-08-16 tmp2.txt 2013-08-31 2013-08-16 total_bytes.dat 2012-10-24 2012-10-24 untitled text 2.txt 2013-08-31 2012-11-05 $
0 コメント:
コメントを投稿