Re: How to append BOM at the beginning of a binary
John Alvord <[email protected]> Mon, 8 Jun 2015 12:25:28 -0700
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <CACd6g0vfVVWXczgDb+wPmQN--i3unieu-PpF7YNRvtQCwdZ5xw@mail.gmail.com> |
--===============0592651277== Content-Type: multipart/alternative; boundary=001a11414886baf9c40518069a30 --001a11414886baf9c40518069a30 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable In general double quotes around. If there are an embedded double quote replace by three double quotes. John Alvord On Jun 8, 2015 10:23 AM, "Francesco Nidito" <[email protected]> wrote: > The following line prints the BOM on STDOUT: perl -CO -e "print > qq{\x{FFEF}}". > > You can incorporate it in your script, anyway, why do you need this? A > UTF-8 document does not need a BOM as there is no bytes-ordering problem = in > UTF-8 by definition... > > > ------------------------------ > =C2=ABWith sufficient thrust, pigs fly just fine. However, this is not > necessarily a good idea. It is hard to be sure where they are going to > land, and it could be dangerous sitting under them as they fly overhead.= =C2=BB > =E2=80=94 R. Callon (rfc1925) > > On 8 June 2015 at 17:48, David Thomas <[email protected]> wrote: > >> On 6/8/15 10:48 AM, Nagy Tamas (TVI-GmbH) wrote: >> > Hi, >> > >> > perl -p -i -e 'BEGIN { printf "%c%c%c", 0xEF, 0xBB, 0xBF }' default.xm= l >> > perl -p -i -e 'BEGIN { print pack "c3", 0xEF, 0xBB, 0xBF }' default.xm= l >> > >> > Both give the same error: >> > >> > Can't find string terminator "'" anywhere before EOF at -e line 1. >> > >> > Is it because of Windows CMD? How to get it work? >> >> Yeah, that's probably due to the peculiar command line parsing in >> Windows. I happen to be on a Mac, but its shell is the same as >> the shell on Linux. >> >> I don't have a Windows machine to test it on, but I think that >> it wants double quotes to enclose the script. Any quotes inside >> the script either have to be single quotes (if the string doesn't >> require variable interpolation), >> >> perl -p -i -e "BEGIN { printf '%c%c%c', 0xEF, 0xBB, 0xBF }" default.xm= l >> >> or escaped double quotes, >> >> perl -p -i -e "BEGIN { printf \"%c%c%c\", 0xEF, 0xBB, 0xBF }" >> default.xml >> >> or use a quoting operator, >> >> perl -p -i -e "BEGIN { printf qq{%c%c%c}, 0xEF, 0xBB, 0xBF }" >> default.xml >> >> >> That would apply to any Perl one-liner you try to run on Windows. >> Most Perl one-liner examples that you are likely to find on the >> web assume a Unix-like shell. >> >> I know all that is a digression from your XML problem, but a solution >> to that problem might be expressible as a one-liner, also, so it's >> important to get past this minor obstacle. >> >> Why do you think you need to put a BOM on your XML file? >> >> -- >> David Thomas >> Sugar Land, Texas >> _______________________________________________ >> Perl-XML mailing list >> [email protected] >> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs >> > > > _______________________________________________ > Perl-XML mailing list > [email protected] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > > --001a11414886baf9c40518069a30 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p dir=3D"ltr">In general double quotes around. If there are an embedded do= uble quote replace by three double quotes.</p> <p dir=3D"ltr">John Alvord</p> <div class=3D"gmail_quote">On Jun 8, 2015 10:23 AM, "Francesco Nidito&= quot; <<a href=3D"mailto:[email protected]">francesco.nidito@gm= ail.com</a>> wrote:<br type=3D"attribution"><blockquote class=3D"gmail_q= uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e= x"><div dir=3D"ltr">The following line prints the BOM on STDOUT:=C2=A0perl = -CO -e "print qq{\x{FFEF}}".<div><br></div><div>You can incorpora= te it in your script, anyway, why do you need this? A UTF-8 document does n= ot need a BOM as there is no bytes-ordering problem in UTF-8 by definition.= ..</div></div><div class=3D"gmail_extra"><br clear=3D"all"><div><div><br> <div> <hr> =C2=ABWith sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead.=C2=BB<br> =E2=80=94 R. Callon (rfc1925)</div></div></div> <br><div class=3D"gmail_quote">On 8 June 2015 at 17:48, David Thomas <span = dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=3D"_blank= ">[email protected]</a>></span> wrote:<br><blockquote class=3D"gma= il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef= t:1ex"><span>On 6/8/15 10:48 AM, Nagy Tamas (TVI-GmbH) wrote:<br> > Hi,<br> ><br> </span><span>> perl -p -i -e 'BEGIN { printf "%c%c%c", 0xE= F, 0xBB, 0xBF }' default.xml<br> > perl -p -i -e 'BEGIN { print pack "c3", 0xEF, 0xBB, 0xBF= }' default.xml<br> ><br> > Both give the same error:<br> ><br> > Can't find string terminator "'" anywhere before EOF= at -e line 1.<br> ><br> > Is it because of Windows CMD? How to get it work?<br> <br> </span>Yeah, that's probably due to the peculiar command line parsing i= n<br> Windows.=C2=A0 I happen to be on a Mac, but its shell is the same as<br> the shell on Linux.<br> <br> I don't have a Windows machine to test it on, but I think that<br> it wants double quotes to enclose the script.=C2=A0 Any quotes inside<br> the script either have to be single quotes (if the string doesn't<br> require variable interpolation),<br> <span><br> =C2=A0 perl -p -i -e "BEGIN { printf '%c%c%c', 0xEF, 0xBB, 0xB= F }" default.xml<br> <br> </span>or escaped double quotes,<br> <span><br> =C2=A0 perl -p -i -e "BEGIN { printf \"%c%c%c\", 0xEF, 0xBB,= 0xBF }" default.xml<br> <br> </span>or use a quoting operator,<br> <br> =C2=A0 perl -p -i -e "BEGIN { printf qq{%c%c%c}, 0xEF, 0xBB, 0xBF }&qu= ot; default.xml<br> <br> <br> That would apply to any Perl one-liner you try to run on Windows.<br> Most Perl one-liner examples that you are likely to find on the<br> web assume a Unix-like shell.<br> <br> I know all that is a digression from your XML problem, but a solution<br> to that problem might be expressible as a one-liner, also, so it's<br> important to get past this minor obstacle.<br> <br> Why do you think you need to put a BOM on your XML file?<br> <div><div><br> --<br> David Thomas<br> Sugar Land, Texas<br> _______________________________________________<br> Perl-XML mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Perl= [email protected]</a><br> To unsubscribe: <a href=3D"http://listserv.ActiveState.com/mailman/mysubs" = target=3D"_blank">http://listserv.ActiveState.com/mailman/mysubs</a><br> </div></div></blockquote></div><br></div> <br>_______________________________________________<br> Perl-XML mailing list<br> <a href=3D"mailto:[email protected]">[email protected]= veState.com</a><br> To unsubscribe: <a href=3D"http://listserv.ActiveState.com/mailman/mysubs" = target=3D"_blank">http://listserv.ActiveState.com/mailman/mysubs</a><br> <br></blockquote></div> --001a11414886baf9c40518069a30-- --===============0592651277== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs --===============0592651277==--