開発環境
- 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(練習問題)2を解いてみる。
その他参考書籍
2.
コード(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 (glob ".* *") { printf "%-25s%20d%20d\n", $_, (stat $_)[8, 9]; }
入出力結果(Terminal)
$ ./sample.pl . 1378004729 1377748321 .. 1377656687 1377596734 .DS_Store 1376708213 1376708285 .out 1356001850 1331880552 __pycache__ 1376199264 1375671467 barney 1373691525 992131200 betty 1373691525 992131200 coconet.dat 1363714109 1319443900 coconet_total.dat 1359273694 1359271200 coconet_total_2.dat 1359273675 1359273675 date.log 1359539830 1359539834 date.txt 1377917277 1335255522 distribute-0.6.34.tar.gz 1358946493 1358946493 fred 1373691525 992131200 gilligan.info 1359618616 1359618616 Gilligan: 1359618082 1359618403 ginger.info 1359618616 1359618616 Ginger: 1359618089 1359618403 hello_world.pl 1364634582 1364023261 html 1372562056 1372562056 link_test 1377917277 1332054588 ln.txt 1377917277 1357027085 ln1.txt 1377917277 1357027085 log 1356001850 1351240266 log_file.txt 1377917277 1311841150 lovey.info 1359618616 1359618616 Lovey: 1359618089 1359618403 ls.out 1377748321 1377748321 maryann.info 1359618616 1359618616 MaryAnn: 1359618089 1359618403 monkeyman.info 1359618616 1359618616 MonkeyMan: 1359618089 1359618403 numbers 1356001850 992131200 Oogaboogoo 1376199264 1360136195 perl_kamimura_blog 1362901396 1356002295 perl_kamimura_blog.html 1378002508 1377921427 perl_program1 1356002263 1332141025 professor.info 1359618616 1359618616 Professor: 1359618089 1359618403 result 1356001850 1342591637 sample 1377917856 1340693917 sample.pl 1378004729 1378004728 sample.py 1378002501 1377921320 sample.txt 1377921243 1374029228 sample_folder 1377917856 1340605913 sample_text 1359360404 992131200 skipper.info 1359618616 1359618616 Skipper: 1359618089 1359618403 some_file 1364628122 1364628122 some_folder 1376199265 1357137716 sortable_hash 1356001850 992131200 standings.db 1360484411 1360484411 test.out 1356001851 1355553807 test.py 1365677990 1364111037 test.txt 1377917277 1332054588 test.txt.out 1364022355 1364023705 test_folder 1376199265 1335769843 test_link 1377917277 1332054588 thurston.info 1359618616 1359618616 Thurston: 1359618089 1359618403 tmp.txt 1377917277 1376622508 tmp1.txt 1377917277 1376622508 tmp2.txt 1377917277 1376622508 total_bytes.dat 1351070414 1351069466 untitled text 2.txt 1377917277 1352078274 $
ちなみにpython3.3の場合。
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3 ## Copyright (C) 2013 by kamimura #-*- coding: utf-8 -*- import glob, os for file in glob.glob('*'): atime, mtime = os.stat(file)[7:9] print("{0:25s}{1:20d}{2:20d}".format( file, atime, mtime))
入出力結果(Terminal)
$ ./sample.py __pycache__ 1376199264 1378005038 barney 1373691525 992131200 betty 1373691525 992131200 coconet.dat 1363714109 1319443900 coconet_total.dat 1359273694 1359271200 coconet_total_2.dat 1359273675 1359273675 date.log 1359539830 1359539834 date.txt 1377917277 1335255522 distribute-0.6.34.tar.gz 1358946493 1358946493 fred 1373691525 992131200 gilligan.info 1359618616 1359618616 Gilligan: 1359618082 1359618403 ginger.info 1359618616 1359618616 Ginger: 1359618089 1359618403 hello_world.pl 1364634582 1364023261 html 1372562056 1372562056 link_test 1377917277 1332054588 ln.txt 1377917277 1357027085 ln1.txt 1377917277 1357027085 log 1356001850 1351240266 log_file.txt 1377917277 1311841150 lovey.info 1359618616 1359618616 Lovey: 1359618089 1359618403 ls.out 1377748321 1377748321 maryann.info 1359618616 1359618616 MaryAnn: 1359618089 1359618403 monkeyman.info 1359618616 1359618616 MonkeyMan: 1359618089 1359618403 numbers 1356001850 992131200 Oogaboogoo 1376199264 1360136195 perl_kamimura_blog 1362901396 1356002295 perl_kamimura_blog.html 1378005790 1378005559 perl_program1 1356002263 1332141025 professor.info 1359618616 1359618616 Professor: 1359618089 1359618403 result 1356001850 1342591637 sample 1377917856 1340693917 sample.pl 1378004729 1378004728 sample.py 1378006033 1378006023 sample.txt 1377921243 1374029228 sample_folder 1377917856 1340605913 sample_text 1359360404 992131200 skipper.info 1359618616 1359618616 Skipper: 1359618089 1359618403 some_file 1364628122 1364628122 some_folder 1376199265 1357137716 sortable_hash 1356001850 992131200 standings.db 1360484411 1360484411 test.out 1356001851 1355553807 test.py 1365677990 1364111037 test.txt 1377917277 1332054588 test.txt.out 1364022355 1364023705 test_folder 1376199265 1335769843 test_link 1377917277 1332054588 thurston.info 1359618616 1359618616 Thurston: 1359618089 1359618403 tmp.txt 1377917277 1376622508 tmp1.txt 1377917277 1376622508 tmp2.txt 1377917277 1376622508 total_bytes.dat 1351070414 1351069466 untitled text 2.txt 1377917277 1352078274 $
pythonのos.statはインデックスがperlのとは少し違うみたい。
入出力結果(Terminal)
$ python Python 3.3.2 (default, May 21 2013, 11:50:39) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.stat('sample.py') posix.stat_result(st_mode=33261, st_ino=61982096, st_dev=234881026, st_nlink=1, st_uid=501, st_gid=20, st_size=236, st_atime=1378006064, st_mtime=1378006023, st_ctime=1378006023) >>> s=os.stat('sample.py') >>> s.st_atime 1378006064.0 >>> s.st_mtime 1378006023.0 >>> quit() $
インデックスに惑わされたくないときは、直接アクセスした方が良さそう。
0 コメント:
コメントを投稿