[Haskell-cafe] How to write elegant Haskell programms? (long
posting)
Eric Mertens
emertens at gmail.com
Mon Jan 29 18:26:05 EST 2007
-- Here's my contribution to the "Haskell" way to do it
import Directory (renameFile)
import System.FilePath
import System.Path.Glob (glob)
import System.Time
basenames = [ "mail.log", "thttpd.log" ]
logdir = "/var/log"
archivedir = "/var/log/archive"
main = forM_ bases $ \base -> do
olds <- glob $ logdir </> base <.> "*.gz"
forM_ olds $ \old -> do
now <- timestamp old
let new = archivedir </> basename <.> now <.> "gz"
printf "mv %s %s" old new
renameFile old new
timestamp f = do
t <- getModificationTime
return $ formatCalendarTime defaultTimeLocale "%Y%m%d" (toUTCTime t)
More information about the Haskell-Cafe
mailing list