[29027] in Perl-Users-Digest
Perl-Users Digest, Issue: 271 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 27 16:29:42 2007
Date: Tue, 27 Mar 2007 13:29:27 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 27 Mar 2007 Volume: 11 Number: 271
Today's topics:
Re: Replacing characters in file <anony-mouse@hole.in.the.wall.com>
Re: Replacing characters in file <someone@example.com>
Re: Replacing characters in file <bik.mido@tiscalinet.it>
Re: Replacing characters in file <rvtol+news@isolution.nl>
Re: Replacing characters in file <rvtol+news@isolution.nl>
Re: Replacing characters in file <someone@example.com>
Re: Replacing characters in file <anony-mouse@hole.in.the.wall.com>
Re: Replacing characters in file <anony-mouse@hole.in.the.wall.com>
Re: Replacing characters in file <anony-mouse@hole.in.the.wall.com>
Re: Replacing characters in file <spamtrap@dot-app.org>
Re: Replacing characters in file <bik.mido@tiscalinet.it>
Re: Replacing characters in file <bik.mido@tiscalinet.it>
Re: Replacing characters in file <tadmc@augustmail.com>
Re: Replacing characters in file <paduille.4060.mumia.w+nospam@earthlink.net>
Re: Replacing characters in file <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 27 Mar 2007 08:55:12 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <270320070855121410%anony-mouse@hole.in.the.wall.com>
In article <eu864k.17g.1@news.isolution.nl>, "Dr.Ruud"
<rvtol+news@isolution.nl> wrote:
> Anony-mouse schreef:
> > Dr.Ruud:
> >> Anony-mouse:
>
> >>> I'm trying to find a way to replace [..] characters 015F (in hex)
> >>> with 015C.
> >>
> >> Is this about double-byte characters?
> >
> > Two characters one after the other in the file.
>
> Please say "bytes" (or "octets") if you mean those. A single character
> can occupy many bytes in a file, think UTF-8.
They are single byte characters as displayed by my hex editor. The
character I want to replace is a "_" (hex 5F) but ONLY when preceeded
by the 01 control character. It needs to be replaced by a "\" character
(hex 5C).
I may also need to swap them back again later, but that's easy to do
once I get it working this way around.
> > I can't simply replace
> > 5F by 5C since there are other 5F characters that must remain
> > unchanged. It's only those preceeded by a 01 that need to be changed.
>
> That answer was already given by Klaus. See also sed or awk.
The SED I tried didn't work because the file contains the DOS EOF
control characters (hex A0) that cause it to abort before reaching the
actual end of the file.
> > The original answer posted doesn't work with my version of Perl
>
> It was a generic answer. What error messages did you get?
Both Mbytes and MOpen are unknown commands, because it's an older
version since I was trying to get as small a filesize as possible to
put on a keyring Flash drive.
_
_/ \___
Anony-mouse says o_/O _/ \
"Eek-eek-eek!" \__/_|_/_|\____/
------------------------------
Date: Mon, 26 Mar 2007 21:19:02 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Replacing characters in file
Message-Id: <aNWNh.15564$__3.7058@edtnps90>
Anony-mouse wrote:
> In article <eu864k.17g.1@news.isolution.nl>, "Dr.Ruud"
> <rvtol+news@isolution.nl> wrote:
>
>>Anony-mouse schreef:
>>>Dr.Ruud:
>>>>Anony-mouse:
>>>>>I'm trying to find a way to replace [..] characters 015F (in hex)
>>>>>with 015C.
>>>>Is this about double-byte characters?
>>>Two characters one after the other in the file.
>>Please say "bytes" (or "octets") if you mean those. A single character
>>can occupy many bytes in a file, think UTF-8.
>
> They are single byte characters as displayed by my hex editor. The
> character I want to replace is a "_" (hex 5F) but ONLY when preceeded
> by the 01 control character. It needs to be replaced by a "\" character
> (hex 5C).
s/(?<=\x01)\x5F/\x5C/g
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Tue, 27 Mar 2007 00:02:36 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Replacing characters in file
Message-Id: <uagg03p954r4ods6sf6gdnt10utqa2el0m@4ax.com>
On Tue, 27 Mar 2007 08:55:12 +1200, Anony-mouse
<anony-mouse@hole.in.the.wall.com> wrote:
>> > The original answer posted doesn't work with my version of Perl
>>
>> It was a generic answer. What error messages did you get?
>
>Both Mbytes and MOpen are unknown commands, because it's an older
>version since I was trying to get as small a filesize as possible to
>put on a keyring Flash drive.
There are no "Mbytes and MOpen commands". There are the bytes and open
pragma(tic module)s. And the -M cmd line switch that provides a very
convenient shortcut in place of a C<use> statement. If your perl
doesn't support these, then it must be *very* old and you'd better
replace it anyway. If its size is excessive for your needs, then you
may package your own distro with a reduced number of accompanying
modules and possibly without documentation. But that's not much
reasonable: more reasonably there are several ways to package a
script, a perl interpreter and all the needed modules into a single
executable file. That may come close to a bare minimum that could be
suitable for your needs.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 27 Mar 2007 00:21:31 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Replacing characters in file
Message-Id: <eu9o3i.194.1@news.isolution.nl>
John W. Krahn schreef:
> s/(?<=\x01)\x5F/\x5C/g
ASCII-alternative:
s!(?=\cA)_!\\!g
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Tue, 27 Mar 2007 00:22:57 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Replacing characters in file
Message-Id: <eu9okl.1k0.1@news.isolution.nl>
Anony-mouse schreef:
> They are single byte characters as displayed by my hex editor. The
> character I want to replace is a "_" (hex 5F) but ONLY when preceeded
> by the 01 control character. It needs to be replaced by a "\"
> character (hex 5C).
You keep talking about characters, so can we assume you have a "text"
file with (because you mentioned DOS) CRLF line endings?
But if your .DAT is a "binary" file, read perlopentut.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Tue, 27 Mar 2007 03:55:22 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Replacing characters in file
Message-Id: <KA0Oh.17035$__3.4928@edtnps90>
Dr.Ruud wrote:
> John W. Krahn schreef:
>
>>s/(?<=\x01)\x5F/\x5C/g
>
> ASCII-alternative:
>
> s!(?=\cA)_!\\!g
ITYM:
s!(?<=\cA)_!\\!g
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Tue, 27 Mar 2007 18:15:06 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <270320071815067111%anony-mouse@hole.in.the.wall.com>
In article <uagg03p954r4ods6sf6gdnt10utqa2el0m@4ax.com>, Michele Dondi
<bik.mido@tiscalinet.it> wrote:
> On Tue, 27 Mar 2007 08:55:12 +1200, Anony-mouse
> <anony-mouse@hole.in.the.wall.com> wrote:
>
> >> > The original answer posted doesn't work with my version of Perl
> >>
> >> It was a generic answer. What error messages did you get?
> >
> >Both Mbytes and MOpen are unknown commands, because it's an older
> >version since I was trying to get as small a filesize as possible to
> >put on a keyring Flash drive.
>
> There are no "Mbytes and MOpen commands". There are the bytes and open
> pragma(tic module)s. And the -M cmd line switch that provides a very
> convenient shortcut in place of a C<use> statement. If your perl
> doesn't support these, then it must be *very* old and you'd better
> replace it anyway. If its size is excessive for your needs, then you
> may package your own distro with a reduced number of accompanying
> modules and possibly without documentation. But that's not much
> reasonable: more reasonably there are several ways to package a
> script, a perl interpreter and all the needed modules into a single
> executable file. That may come close to a bare minimum that could be
> suitable for your needs.
The original reply was:
perl -Mbytes -Mopen=IO,:raw -pi.bak -e
"s/\x01\x5c/\x01\x5f/g" test.dat
My version of Perl throws up an error unless I remove both of the first
two parameters / switches / commands / whatever you want to call them.
_
_/ \___
Anony-mouse says o_/O _/ \
"Eek-eek-eek!" \__/_|_/_|\____/
------------------------------
Date: Tue, 27 Mar 2007 18:19:20 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <270320071819202440%anony-mouse@hole.in.the.wall.com>
In article <aNWNh.15564$__3.7058@edtnps90>, "John W. Krahn"
<someone@example.com> wrote:
> Anony-mouse wrote:
> > In article <eu864k.17g.1@news.isolution.nl>, "Dr.Ruud"
> > <rvtol+news@isolution.nl> wrote:
> >
> >>Anony-mouse schreef:
> >>>Dr.Ruud:
> >>>>Anony-mouse:
> >>>>>I'm trying to find a way to replace [..] characters 015F (in hex)
> >>>>>with 015C.
> >>>>Is this about double-byte characters?
> >>>Two characters one after the other in the file.
> >>Please say "bytes" (or "octets") if you mean those. A single character
> >>can occupy many bytes in a file, think UTF-8.
> >
> > They are single byte characters as displayed by my hex editor. The
> > character I want to replace is a "_" (hex 5F) but ONLY when preceeded
> > by the 01 control character. It needs to be replaced by a "\" character
> > (hex 5C).
>
> s/(?<=\x01)\x5F/\x5C/g
I tried things like that in SED, but it didn't work because it stops
when it hits an EOF character before it reaches the real end of the
file.
I think I also tried a similar thing in Perl by taking out the -Mbytes
and -Mopen commands from the original reply and got the same aborted
result.
_
_/ \___
Anony-mouse says o_/O _/ \
"Eek-eek-eek!" \__/_|_/_|\____/
------------------------------
Date: Tue, 27 Mar 2007 18:23:39 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <270320071823398064%anony-mouse@hole.in.the.wall.com>
In article <eu9okl.1k0.1@news.isolution.nl>, "Dr.Ruud"
<rvtol+news@isolution.nl> wrote:
> Anony-mouse schreef:
>
> > They are single byte characters as displayed by my hex editor. The
> > character I want to replace is a "_" (hex 5F) but ONLY when preceeded
> > by the 01 control character. It needs to be replaced by a "\"
> > character (hex 5C).
>
> You keep talking about characters, so can we assume you have a "text"
> file with (because you mentioned DOS) CRLF line endings?
>
> But if your .DAT is a "binary" file, read perlopentut.
Call them whatever you want, but I have said all along that the
"characters" are 01 and 5F in hex ... 01 is not an ASCII character, but
is a control character for "start of record" (or something like that
from memory).
I have also said that it is a .DAT file containing various control
characters, so it can't be a plain text file, which is why I never said
"text file" anywhere.
If it was a simple text file, then SED would have worked.
_
_/ \___
Anony-mouse says o_/O _/ \
"Eek-eek-eek!" \__/_|_/_|\____/
------------------------------
Date: Tue, 27 Mar 2007 02:23:32 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Replacing characters in file
Message-Id: <m2k5x32oij.fsf@local.wv-www.com>
Anony-mouse <anony-mouse@hole.in.the.wall.com> writes:
> perl -Mbytes -Mopen=IO,:raw -pi.bak -e
> "s/\x01\x5c/\x01\x5f/g" test.dat
>
> My version of Perl throws up an error unless I remove both of the first
> two parameters / switches / commands / whatever you want to call them.
The bytes and open pragmatic modules are present as core modules in the
oldest Perl I have on hand - 5.6.0. If you're using that or newer, it's
either misconfigured and can't find its standard modules, or they've been
deleted.
Exactly what error is being produced?
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 27 Mar 2007 11:52:47 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Replacing characters in file
Message-Id: <09qh03l64colqt36u8opomt4fmcgg6v4ae@4ax.com>
On Tue, 27 Mar 2007 18:19:20 +1200, Anony-mouse
<anony-mouse@hole.in.the.wall.com> wrote:
>> s/(?<=\x01)\x5F/\x5C/g
>
>I tried things like that in SED, but it didn't work because it stops
>when it hits an EOF character before it reaches the real end of the
>file.
The above is an extended regex that afaik won't work in sed anyway.
>I think I also tried a similar thing in Perl by taking out the -Mbytes
>and -Mopen commands from the original reply and got the same aborted
>result.
s/commands/arguments/; so just don't take them out!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 27 Mar 2007 11:54:16 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Replacing characters in file
Message-Id: <pcqh03lihgovctuald50dqfopsrgv7jsk0@4ax.com>
On Tue, 27 Mar 2007 18:15:06 +1200, Anony-mouse
<anony-mouse@hole.in.the.wall.com> wrote:
>The original reply was:
>
> perl -Mbytes -Mopen=IO,:raw -pi.bak -e
> "s/\x01\x5c/\x01\x5f/g" test.dat
>
>My version of Perl throws up an error unless I remove both of the first
>two parameters / switches / commands / whatever you want to call them.
I understood that. Now, did you understand I suggested you to upgrade?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 27 Mar 2007 04:42:43 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Replacing characters in file
Message-Id: <slrnf0hpoj.ic8.tadmc@tadmc30.august.net>
Anony-mouse <anony-mouse@hole.in.the.wall.com> wrote:
> 01 is not an ASCII character,
Yes it is.
> but
> is a control character
Many ASCII characters are control characters.
> for "start of record" (or something like that
> from memory).
Its name, defined by ASCII, is Start Of Heading (SOH).
> I have also said that it is a .DAT file containing various control
> characters, so it can't be a plain text file, which is why I never said
> "text file" anywhere.
Text files can, and nearly always do, contain control
characters (LF, line feed, for example).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 27 Mar 2007 12:23:59 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: Replacing characters in file
Message-Id: <z18Oh.15609$PL.14279@newsread4.news.pas.earthlink.net>
On 03/27/2007 01:23 AM, Anony-mouse wrote:
> In article <eu9okl.1k0.1@news.isolution.nl>, "Dr.Ruud"
> <rvtol+news@isolution.nl> wrote:
>
>> [...]
>> But if your .DAT is a "binary" file, read perlopentut.
>
> Call them whatever you want, but I have said all along that the
> "characters" are 01 and 5F in hex ... 01 is not an ASCII character, but
> is a control character for "start of record" (or something like that
> from memory).
>
> I have also said that it is a .DAT file containing various control
> characters, so it can't be a plain text file, which is why I never said
> "text file" anywhere.
>
> If it was a simple text file, then SED would have worked.
> _
> _/ \___
> Anony-mouse says o_/O _/ \
> "Eek-eek-eek!" \__/_|_/_|\____/
So I take it that you want us to help you write a program that can make
modifications to a binary file, and you want that program to fit on a
USB key.
Why do you want to do this?
------------------------------
Date: Tue, 27 Mar 2007 14:49:29 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Replacing characters in file
Message-Id: <Z9aOh.3620$J21.675@trndny03>
Anony-mouse wrote:
> it stops
> when it hits an EOF character before it reaches the real end of the
> file.
Your text file contains an EOF before the end of the file? That is hmmm,
well, unusual, don't you think?
Maybe you should look into fixing the software that created this file?
If on the other hand you don't have a text file, then maybe it is time to
stop treating it as a text file but start handling it as a binary file
instead.
jue
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 271
**************************************