I'm trying to remove the \r from the end of lines when using BS.getLine
. I've tried using hSetNewlineMode
and it works with getLine
but not with BS.getLine
:
import qualified Data.ByteString.Char8 as BS
import Data.ByteString (ByteString)
import System.IO (hSetNewlineMode, universalNewlineMode, stdin)
main = do
hSetNewlineMode stdin universalNewlineMode
-- s <- BS.pack `fmap` getLine -- \r removed
s <- BS.getLine -- \r not removed
putStrLn $ show s
-- to test: perl -e 'print "this\r\n"' | runhaskell program.hs
Is there something else I should be doing?