看板 Perl 關於我們 聯絡資訊
大家好,小弟現在有一個在windows下接收data所得到的ascii code file, 想將此file在linux系統下轉成十六進制, 但發現原本應該是十六進制"0A"的ascii符號一直沒辦法被判讀到, (PS.其他ascii字元目前沒發現問題) 想請問板上高手們是否有相關經驗呢? 以下是小弟的簡單程式碼: open(PM, "./parser.log") binmode PM; foreach(<PM>) { chomp($_); $line = $_; my $out = unpack('H*', $_); print "$out" } 真的麻煩板上高手了,謝謝阿!!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.129.31.153 ※ 文章網址: https://www.ptt.cc/bbs/Perl/M.1432056343.A.9ED.html
CindyLinz: chomp 把 "\n" 字元 (就是 0A) 刪掉了呀~ 05/20 01:38
mattheww: 感謝C大!原來是我一直弄錯方向 05/20 02:14
mattheww: 一直以為是不同系統的問題,謝謝你!! 05/20 02:14
flu: 有用binmode, line input mode,只chomp掉\x0a, 檔案是windows 05/20 02:22
flu: 那輸出後不就一堆 \x0d 遺留下來了?? 05/20 02:23
flu: 更正:檔案來源是windows 05/20 02:23
mattheww: 試了一下,好像不論有沒有加binmode,"0d"都會留下來 05/20 13:04