Open Source WEB

2006-10-19 [Haskell] トドちゃんカウンタ

結城さんのトドちゃんを数えるPerlスクリプトのHaskell版

カレントディレクトリにある *.txt ファイル中の行頭が todo: であるような行の数を数えて,ファイル毎の todo の数と,トータルを表示する.

% countTodo.lhs
2006-10-15.txt: 3
2006-10-16.txt: 12
2006-10-17.txt: 8
2006-10-18.txt: 20
ε(     v ゜ω゜) < TODO 43 頭♪

てな感じ.

#!/usr/bin/env runhaskell
\begin{code}
module Main (main) where

import Control.Monad (foldM)
import Data.Char (toLower)
import Data.List (isPrefixOf,isSuffixOf)
import System.Directory (getCurrentDirectory,getDirectoryContents)

import UTF8        -- 俺様UTF8.hs

main :: IO ()
main =   getCurrentDirectory 
     >>= getDirectoryContents
     >>= foldM countTodo 0 . filter (".txt" `isSuffixOf`)
     >>= putStrLn . toUTF8 . todo

todo :: Int -> String
todo c = "ε(     v ゜ω゜) < TODO "++show c++" 頭♪"

countTodo :: Int -> String -> IO Int
countTodo c f
 = flip catch 
        (return . const c)
        (do { cs <- readFile f
            ; let len = length  $ filter (("todo:" `isPrefixOf`).map toLower)
                                $ lines cs
            ; putStrLn $ ((f ++ ": ")++) $ show len
            ; return (c+len)
            })
\end{code}

--nobsun


Name:
Comment:
EyeUbLoOFtbZQv: (Tue Dec 30 08:46:34 2008 )
BgSdcN
googlaaa: (Thu Apr 23 19:17:52 2009 )
UC8w9Z http://google.com
SjQxpSiTA: (Tue Sep 15 20:23:39 2009 )
doors.txt;10;15
cjdwDLHakPZKQ: (Sun Oct 11 23:09:05 2009 )
awegaw1.txt;2;5
Faggot56: (Fri Oct 23 02:28:04 2009 )
The basic purpose, scope and principles of the document remain  unchanged. ,
sandy: (Sun May 30 02:58:43 2010 )
jlIISi http://f8j3ndYbs83Bbq06Wlavp.com
samanta: (Wed Sep 1 11:20:16 2010 )
icQZRo http://djb3jDdmjckow30cnjcmd61l0dy.com
canadian drugs onlin: (Thu Feb 17 17:58:25 2011 )
Very nice post, good luck! ;-)
jonn1: (Tue Jul 19 02:19:30 2011 )
comment1,
jonn1: (Tue Jul 19 02:41:20 2011 )
comment4,
crysty: (Sun Jul 31 09:10:47 2011 )
d3HvYo http://ueNx8wqkk3Mnd.com
marmont: (Sun Jul 31 13:38:15 2011 )
63UMlU http://dcYhnkl3mg78Nsfi.com
trinity: (Sun Jul 31 14:02:54 2011 )
2mvoNC http://www.tdHn2o99genVcoe.net
geoge: (Sun Jul 31 16:20:37 2011 )
gT5K74 http://www.nYwl9n4vb4BsdL2kt.net
marmont: (Tue Aug 23 06:03:37 2011 )
9kv1FC http://dfb6WkPnj4bYud6v2Oxt.com
trinity: (Tue Aug 23 18:27:32 2011 )
rIAWUj http://cbTqto62bOpdn54BcCqp.net
trinity: (Wed Aug 24 07:24:42 2011 )
GCXG3X http://www.ErjfoeBnen03bY1mB7bz.com
joseph: (Wed Aug 24 20:05:01 2011 )
6R4jx1 http://wnbUj5n0mXqpcvm27Hms.biz
b0SamueL0b: (Sat Sep 10 07:44:20 2011 )
+z$8frZdyL%68pSU/:>w<:E3.lG-!XIB
Aeoxxomr: (Sun Sep 11 21:55:52 2011 )
Where are you calling from?
uiTomas0k: (Fri Sep 16 00:00:51 2011 )
http://BPsU(-Zv8B&/LCOJtd6WZB!+%v!H(&v9.com
geogen: (Tue Oct 4 21:59:45 2011 )
47lxuS http://6u0n0h0g4gUJK0UP.com
trinity: (Wed Oct 5 14:53:35 2011 )
kmXs5L http://DUIyaPoAghaOOv2A.net
joseph: (Thu Oct 6 07:42:33 2011 )
AJy09O http://aAQKOiop2iLyMpBz.biz
Wilman: (Thu Oct 6 14:13:55 2011 )
n59EkK http://CA6HyasJOMgLwTQE.net
vwvzksmoij: (Fri Oct 21 22:20:37 2011 )
csfhyptt, http://www.cfxuystaqi.com vkobuxxpuv
Wilman: (Fri Oct 28 23:25:31 2011 )
BH1x6x http://M8bJXXT7yzZFp1CH.com
gcmcieqgdb: (Sun Nov 27 11:54:21 2011 )
fksgpptt, http://www.ydlxqucrmx.com wmbcvpjuxj
xsrxgrenae: (Sun Nov 27 21:14:38 2011 )
wjgklptt, http://www.achmzrtggu.com msaslzijtf
DrZoibergLo: (Tue Nov 29 18:27:04 2011 )
http://www.QKiMt6vfLbn1bD0zxU9QchzPHO25ZYPy.com
joseph: (Tue Jan 3 09:14:17 2012 )
http://www.l4kQDD30zNsyoG7pFkTOj6m6mXdUqdwF.com
trinity: (Tue Jan 3 10:18:26 2012 )
http://www.NIzi0QxjqKwVZYJ0oEPJhqfCBoLXzubW.com
pHLMEZJ7: (Wed Jan 25 00:10:05 2012 )
2vunns http://www.RUWE5gOde94HqsfDYIh3uBfJfSMdiDSG.com
Oalwgqpu: (Thu Jan 26 05:40:15 2012 )
Photography

このサイトは、 IPA の「平成15年度オープンソフトウエア活用基盤整備事業」 の委託事業として開発されたKahuaで試験的に運用しております。

Copyright (c) 2004-2007 株式会社タイムインターメディア About Us