
agent
Novice
Aug 4, 2008, 8:38 PM
Views: 418
|
|
Re: [acchao] Help with binary file [\r\n] removal
|
|
|
hi hmm that's weird but on my system it works fine, i'd tested it again either with mine and your input data and it seems to generate proper results. I've used the hex editor to generate the files ;) ".=" concatenate value of left operand with right operand, that means if you have $a scalar with string value "ABBA", and you make statement like $a .= " ROCKS", you'll get "ABBA ROCKS" in $a ;) "s/(.{2})\r\n/$1/sg" (.{2}) matches any two characters (except newline) $1 represents result of match in first parentheses so (.{2})\r\n will give you match like "X X 0x0D 0x0A" where X is any value except newline. /g means global matching as you already know /s forces to treat the string as single line (it will allow "." to match newline) all this means that we try to match "X X 0x0D 0x 0A" string and put only the "X X" characters on it's place globally. to see how while loop read lines try: while (<INPUT>) { print OUTPUT $_; print OUTPUT "0000000000000000000"; } And look into the output file you'll get each line separated by "00000000000" string; Anyway i have no idea why this code doesn't work for you. Can you post the output you get from my and your input files? Then maybe we'll find out what's going on :) regards
(This post was edited by agent on Aug 4, 2008, 8:41 PM)
|