RE: How to append BOM at the beginning of a binary

Nids <[email protected]> Mon, 8 Jun 2015 21:34:34 +0100
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
--===============0299191557==
Content-Type: multipart/alternative;
	boundary="_C2E97D0A-C353-427C-8506-D41366E3A546_"

--_C2E97D0A-C353-427C-8506-D41366E3A546_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

I am on Windows.

Typed on a very small keyboard...

-----Original Message-----
From: "John Alvord" <[email protected]>
Sent: =E2=80=8E08/=E2=80=8E06/=E2=80=8E2015 20:25
To: "Francesco Nidito" <[email protected]>
Cc: "[email protected]" <[email protected]>=
; "David Thomas" <[email protected]>
Subject: Re: How to append BOM at the beginning of a binary

In general double quotes around. If there are an embedded double quote repl=
ace by three double quotes.
John Alvord
On Jun 8, 2015 10:23 AM, "Francesco Nidito" <[email protected]> wr=
ote:

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 nece=
ssarily a good idea. It is hard to be sure where they are going to land, an=
d 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.xml
> perl -p -i -e 'BEGIN { print pack "c3", 0xEF, 0xBB, 0xBF }' default.xml
>
> 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.xml

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=

--_C2E97D0A-C353-427C-8506-D41366E3A546_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=
=3Dutf-8"></head><body><div><div style=3D"font-family: Calibri,sans-serif; =
font-size: 11pt;">I am on Windows.<br><br>Typed on a very small keyboard...=
</div></div><div dir=3D"ltr"><hr><span style=3D"font-family: Calibri,sans-s=
erif; font-size: 11pt; font-weight: bold;">From: </span><span style=3D"font=
-family: Calibri,sans-serif; font-size: 11pt;"><a href=3D"mailto:johngraham=
[email protected]">John Alvord</a></span><br><span style=3D"font-family: Cal=
ibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span st=
yle=3D"font-family: Calibri,sans-serif; font-size: 11pt;">=E2=80=8E08/=E2=
=80=8E06/=E2=80=8E2015 20:25</span><br><span style=3D"font-family: Calibri,=
sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style=3D"=
font-family: Calibri,sans-serif; font-size: 11pt;"><a href=3D"mailto:france=
[email protected]">Francesco Nidito</a></span><br><span style=3D"font-fa=
mily: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc: </span><=
span style=3D"font-family: Calibri,sans-serif; font-size: 11pt;"><a href=3D=
"mailto:[email protected]">[email protected]=
m</a>; <a href=3D"mailto:[email protected]">David Thomas</a></span><b=
r><span style=3D"font-family: Calibri,sans-serif; font-size: 11pt; font-wei=
ght: bold;">Subject: </span><span style=3D"font-family: Calibri,sans-serif;=
 font-size: 11pt;">Re: How to append BOM at the beginning of a binary</span=
><br><br></div><p dir=3D"ltr">In general double quotes around. If there are=
 an embedded double quote replace by three double quotes.</p>=0A=
<p dir=3D"ltr">John Alvord</p>=0A=
<div class=3D"gmail_quote">On Jun 8, 2015 10:23 AM, "Francesco Nidito" &lt;=
<a href=3D"mailto:[email protected]">[email protected]</a=
>&gt; wrote:<br type=3D"attribution"><blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(2=
04, 204, 204); border-left-width: 1px; border-left-style: solid;"><div dir=
=3D"ltr">The following line prints the BOM on STDOUT:&nbsp;perl -CO -e "pri=
nt qq{\x{FFEF}}".<div><br></div><div>You can incorporate it in your script,=
 anyway, why do you need this? A UTF-8 document does not need a BOM as ther=
e is no bytes-ordering problem in UTF-8 by definition...</div></div><div cl=
ass=3D"gmail_extra"><br clear=3D"all"><div><div><br>=0A=
    <div>=0A=
      <hr>=0A=
      =C2=ABWith sufficient thrust, pigs fly just fine. However, this is=0A=
not necessarily a good idea. It is hard to be sure where they=0A=
are going to land, and it could be dangerous sitting under them=0A=
as they fly overhead.=C2=BB<br>=0A=
=E2=80=94 R. Callon (rfc1925)</div></div></div>=0A=
<br><div class=3D"gmail_quote">On 8 June 2015 at 17:48, David Thomas <span =
dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank=
">[email protected]</a>&gt;</span> wrote:<br><blockquote class=3D"gma=
il_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-lef=
t-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: sol=
id;"><span>On 6/8/15 10:48 AM, Nagy Tamas (TVI-GmbH) wrote:<br>=0A=
&gt; Hi,<br>=0A=
&gt;<br>=0A=
</span><span>&gt; perl -p -i -e 'BEGIN { printf "%c%c%c", 0xEF, 0xBB, 0xBF =
}' default.xml<br>=0A=
&gt; perl -p -i -e 'BEGIN { print pack "c3", 0xEF, 0xBB, 0xBF }' default.xm=
l<br>=0A=
&gt;<br>=0A=
&gt; Both give the same error:<br>=0A=
&gt;<br>=0A=
&gt; Can't find string terminator "'" anywhere before EOF at -e line 1.<br>=
=0A=
&gt;<br>=0A=
&gt; Is it because of Windows CMD? How to get it work?<br>=0A=
<br>=0A=
</span>Yeah, that's probably due to the peculiar command line parsing in<br=
>=0A=
Windows.&nbsp; I happen to be on a Mac, but its shell is the same as<br>=0A=
the shell on Linux.<br>=0A=
<br>=0A=
I don't have a Windows machine to test it on, but I think that<br>=0A=
it wants double quotes to enclose the script.&nbsp; Any quotes inside<br>=
=0A=
the script either have to be single quotes (if the string doesn't<br>=0A=
require variable interpolation),<br>=0A=
<span><br>=0A=
&nbsp; perl -p -i -e "BEGIN { printf '%c%c%c', 0xEF, 0xBB, 0xBF }" default.=
xml<br>=0A=
<br>=0A=
</span>or escaped double quotes,<br>=0A=
<span><br>=0A=
&nbsp; perl -p -i -e "BEGIN { printf \"%c%c%c\", 0xEF, 0xBB, 0xBF }" defaul=
t.xml<br>=0A=
<br>=0A=
</span>or use a quoting operator,<br>=0A=
<br>=0A=
&nbsp; perl -p -i -e "BEGIN { printf qq{%c%c%c}, 0xEF, 0xBB, 0xBF }" defaul=
t.xml<br>=0A=
<br>=0A=
<br>=0A=
That would apply to any Perl one-liner you try to run on Windows.<br>=0A=
Most Perl one-liner examples that you are likely to find on the<br>=0A=
web assume a Unix-like shell.<br>=0A=
<br>=0A=
I know all that is a digression from your XML problem, but a solution<br>=
=0A=
to that problem might be expressible as a one-liner, also, so it's<br>=0A=
important to get past this minor obstacle.<br>=0A=
<br>=0A=
Why do you think you need to put a BOM on your XML file?<br>=0A=
<div><div><br>=0A=
--<br>=0A=
David Thomas<br>=0A=
Sugar Land, Texas<br>=0A=
_______________________________________________<br>=0A=
Perl-XML mailing list<br>=0A=
<a href=3D"mailto:[email protected]" target=3D"_blank">Perl=
[email protected]</a><br>=0A=
To unsubscribe: <a href=3D"http://listserv.ActiveState.com/mailman/mysubs" =
target=3D"_blank">http://listserv.ActiveState.com/mailman/mysubs</a><br>=0A=
</div></div></blockquote></div><br></div>=0A=
<br>_______________________________________________<br>=0A=
Perl-XML mailing list<br>=0A=
<a href=3D"mailto:[email protected]">[email protected]=
veState.com</a><br>=0A=
To unsubscribe: <a href=3D"http://listserv.ActiveState.com/mailman/mysubs" =
target=3D"_blank">http://listserv.ActiveState.com/mailman/mysubs</a><br>=0A=
<br></blockquote></div>=0A=
</body></html>=

--_C2E97D0A-C353-427C-8506-D41366E3A546_--


--===============0299191557==
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

--===============0299191557==--