Thomas Liebezeit wrote:
Hello,

Hello,

I'm triying to do some substitutions on an  pdf file.


perl -p -i~ -w -e "s/A/B/;" file.pdf

This works as intended, except:  perl adds 0x0D (Windows \n)  :-/
as a  HEX diff shows.
How can I work around this? Is there something like binmode()?

You should be able to do this with the open module:

perl -Mopen=:bytes -i~ -pe "s/A/B/" file.pdf

Or it should work in slurp mode if the files are small enough to fit in memory:

perl -i~ -0777pe "s/A/B/" file.pdf


BTW your substitution operator replaces only the first 'A' it finds with 'B'. If you want to replace all 'A's with 'B's then you have to use the /g option on the substitution: s/A/B/g. And it you are only really replacing one character with another then you should probably use transliteration instead: tr/A/B/.



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to