[29030] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 274 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 27 21:14:21 2007

Date: Tue, 27 Mar 2007 18:14:16 -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: 274

Today's topics:
    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 <rvtol+news@isolution.nl>
    Re: Replacing characters in file <rvtol+news@isolution.nl>
    Re: Replacing characters in file <jurgenex@hotmail.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 <uri@stemsystems.com>
        Troubleshooting cpan <socyl@987jk.com.invalid>
    Re: Troubleshooting cpan usenet@DavidFilmer.com
        Writing a system log monitor <BradenM@SonomaComputer.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 28 Mar 2007 08:52:44 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <280320070852442883%anony-mouse@hole.in.the.wall.com>

In article <Z9aOh.3620$J21.675@trndny03>, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

> 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.

It's not a text file. As I said it's a .DAT file that contains control
characters, including EOF ones.  :o\
                           _
                         _/ \___
 Anony-mouse says     o_/O _/   \
  "Eek-eek-eek!"       \__/_|_/_|\____/


------------------------------

Date: Wed, 28 Mar 2007 08:55:35 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <280320070855353201%anony-mouse@hole.in.the.wall.com>

In article <pcqh03lihgovctuald50dqfopsrgv7jsk0@4ax.com>, Michele Dondi
<bik.mido@tiscalinet.it> wrote:

> 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?

As I said in a previous message. I was using an old version that was
nice and small (around 300K) to fit on a Flash drive. Obvoiusly this
old version doesn't like the Mbytes and Mopen options. 

I'm trying to get the Active Perl that the original person was using,
but it's 15MB and I'm on a limited time dial-up account, so it will
take a while before I can even try it. Although that's the installer
filesize, it may well turn out that the version of Perl is simply too
big for my needs anyway.

                           _
                         _/ \___
 Anony-mouse says     o_/O _/   \
  "Eek-eek-eek!"       \__/_|_/_|\____/


------------------------------

Date: Wed, 28 Mar 2007 09:00:08 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <280320070900089664%anony-mouse@hole.in.the.wall.com>

In article <z18Oh.15609$PL.14279@newsread4.news.pas.earthlink.net>,
"Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net> wrote:

> 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.
> 
> 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?

I'm really beginning to think it's not worth wasting my time with Perl
at all. There must be an easy (and small) way to achieve this.  :o\
                           _
                         _/ \___
 Anony-mouse says     o_/O _/   \
  "Eek-eek-eek!"       \__/_|_/_|\____/


------------------------------

Date: Wed, 28 Mar 2007 00:03:30 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Replacing characters in file
Message-Id: <eucbej.1fc.1@news.isolution.nl>

John W. Krahn schreef:
> Dr.Ruud:
>> John W. Krahn:

>>> s/(?<=\x01)\x5F/\x5C/g
>> 
>> ASCII-alternative:
>> 
>>   s!(?=\cA)_!\\!g
> 
> ITYM:
> 
>     s!(?<=\cA)_!\\!g

Yes, thanks!

-- 
Affijn, Ruud

"Gewoon is een tijger."


------------------------------

Date: Wed, 28 Mar 2007 00:22:59 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Replacing characters in file
Message-Id: <eucck7.1hk.1@news.isolution.nl>

Anony-mouse schreef:
> Dr.Ruud:
>> Anony-mouse:

>>> 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).

01 is an ASCII character.

I think it is best that you rephrase your question to something like:
I want to replace, in a binary file on a DOS-type system, the
two-byte-sequence "0x01 0x5F" by "0x01 0x5C".

You should also tell something about the size of the file. If the file
fits easily in memory, it is much easier to do the replacement. If the
file is way big so it needs to be processed in chunks, then the 0x01
could be the last byte of a chunk, which complicates things a little.


> 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.

A .DAT file (whatever that means) containing various control characters,
can be a perfectly normal plain text file.
See also http://filext.com/detaillist.php?extdetail=.DAT

> If it was a simple text file, then SED would have worked.

Some seds can streamedit binary files as well.

-- 
Affijn, Ruud

"Gewoon is een tijger."



------------------------------

Date: Tue, 27 Mar 2007 23:53:31 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Replacing characters in file
Message-Id: <%7iOh.1641$Rp2.877@trndny04>

Anony-mouse wrote:
> In article <Z9aOh.3620$J21.675@trndny03>, "Jürgen Exner"
>> 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.
>
> It's not a text file. As I said it's a .DAT file

Whatever that is supposed to mean.
A file name ending of .DAT doesn't imply anything as to the content of the 
file.

> that contains control
> characters, including EOF ones.  :o\

Well, if it is not a text file but a binary file, then it isn't very 
meaningful to talk about characters.
It would have been much less confusing if you had said "I have a two-byte 
sequence"01 5F" (denoted in hex) and like to replace it with "01 5C" .

I still don't understand why a simply
    s/\x01\x5F/\x01\x5C/g
shouldn't work.

jue 




------------------------------

Date: Wed, 28 Mar 2007 12:40:14 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <280320071240147805%anony-mouse@hole.in.the.wall.com>

In article <%7iOh.1641$Rp2.877@trndny04>, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

> Anony-mouse wrote:
> > In article <Z9aOh.3620$J21.675@trndny03>, "Jürgen Exner"
> >> 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.
> >
> > It's not a text file. As I said it's a .DAT file
> 
> Whatever that is supposed to mean.
> A file name ending of .DAT doesn't imply anything as to the content of the 
> file.

Although not necessarily true, it does imply that it's not a simple
 .TXT file.  



> > that contains control
> > characters, including EOF ones.  :o\
> 
> Well, if it is not a text file but a binary file, then it isn't very 
> meaningful to talk about characters.
> It would have been much less confusing if you had said "I have a two-byte 
> sequence"01 5F" (denoted in hex) and like to replace it with "01 5C".

Symantics (or pendaticism, whichever you prefer). It still means the
same thing and some people seem to have understood what I was saying,
while others simply want to get picky about terminology.



> I still don't understand why a simply
>     s/\x01\x5F/\x01\x5C/g
> shouldn't work.

It doesn't work in SED because SED aborts when it hits the first EOF
character and so doesn't complete the file.

In the version of Perl I've been using it simply does nothing - I get a
completely empty result file. I'll have to wait until I finish
downloading Active Perl and see what happens there, but that may be too
big in filesize for my needs.


                           _
                         _/ \___
 Anony-mouse says     o_/O _/   \
  "Eek-eek-eek!"       \__/_|_/_|\____/


------------------------------

Date: Wed, 28 Mar 2007 12:45:05 +1200
From: Anony-mouse <anony-mouse@hole.in.the.wall.com>
Subject: Re: Replacing characters in file
Message-Id: <280320071245055360%anony-mouse@hole.in.the.wall.com>

In article <eucck7.1hk.1@news.isolution.nl>, "Dr.Ruud"
<rvtol+news@isolution.nl> wrote:

> Anony-mouse schreef:
> > Dr.Ruud:
> >> Anony-mouse:
> 
> >>> 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).
> 
> 01 is an ASCII character.

Yes, an ASCII control character. One of many different one sin the
file, so it's not a simple ASCII / text file.



> I think it is best that you rephrase your question to something like:
> I want to replace, in a binary file on a DOS-type system, the
> two-byte-sequence "0x01 0x5F" by "0x01 0x5C".

The terminology is irrelevant since some people have obvoiusly
understood.



> You should also tell something about the size of the file. If the file
> fits easily in memory, it is much easier to do the replacement. If the
> file is way big so it needs to be processed in chunks, then the 0x01
> could be the last byte of a chunk, which complicates things a little.

The size of the .DAT file is probably irrelevant too since it's under
10K.



> > 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.
> 
> A .DAT file (whatever that means) containing various control characters,
> can be a perfectly normal plain text file.
> See also http://filext.com/detaillist.php?extdetail=.DAT

If I'd meant a plain ASCII / text file than I would have said .TXT file.



> > If it was a simple text file, then SED would have worked.
> 
> Some seds can streamedit binary files as well.

Then maybe I need a different version, but every version I've looked at
(which probably isn't ALL of them) says that under DOS finding a EOF
character will cause it to stop processing the file.
                           _
                         _/ \___
 Anony-mouse says     o_/O _/   \
  "Eek-eek-eek!"       \__/_|_/_|\____/


------------------------------

Date: Tue, 27 Mar 2007 19:59:32 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Replacing characters in file
Message-Id: <x7zm5ykwsr.fsf@mail.sysarch.com>

>>>>> "A" == Anony-mouse  <anony-mouse@hole.in.the.wall.com> writes:

  A> Yes, an ASCII control character. One of many different one sin the
  A> file, so it's not a simple ASCII / text file.

you seem to have this odd conception of what makes a binary or text
file. it is NEVER the suffix itself (however much redmond thinks so). so
stop calling your file whatever you want and start describing its actual
contents.

  A> The size of the .DAT file is probably irrelevant too since it's under
  A> 10K.

so slurp it in, do the s///g and spew it out. wow!

  >> > 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.
  >> 
  >> A .DAT file (whatever that means) containing various control characters,
  >> can be a perfectly normal plain text file.
  >> See also http://filext.com/detaillist.php?extdetail=.DAT

  A> If I'd meant a plain ASCII / text file than I would have said .TXT file.

no. there is no such thing as a TXT file. there is a .TXT suffix. maybe
it is a normal text file if no one lied about the suffix but that
happens all the time. as i said, stop calling a file by its suffix. it
is wrong, not portable, makes no sense, etc.


  A> Then maybe I need a different version, but every version I've looked at
  A> (which probably isn't ALL of them) says that under DOS finding a EOF
  A> character will cause it to stop processing the file.

again, there is NO eof character in a general sense. stop saying
that. you are obviously stuck on redmondware which has inherited the
ancient practice of ending 'text' files with ^Z. but you keep claiming
your file is not a text file so it shouldn't matter if there is a ^Z in
there. so your falacious thinking is boxing you in. is it text and ^Z
matters or is it binary and ^Z doesn't matter?

since you seem to think it is a binary file, then sed is not for you as
it is a LINE oriented stream editor. neither is perl in a line by line
mode. and on redmond, maybe even perl will stop reading a file in 'text'
mode (see perldoc -f binmode) when it hits ^Z. in that case you need to
slurp the file in binary mode and do your s/// over the whole file with
NO regard to lines or ^Z. you can do this with File::Slurp with the
binary option enabled. do not do this with perl's -p/-n options as they
will run in text mode. i doubt even using -0777 will work as nothing is
telling perl or winblows that your file is binary so the ^Z will hit
you.

now do the right thing already, slurp it in in binary more, clean up the
mess, and write it out. and end this interminable thread!

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Tue, 27 Mar 2007 20:57:42 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Troubleshooting cpan
Message-Id: <euc0g6$pv$1@reader2.panix.com>




When I try to use the cpan command, attempts to fetch files (e.g.
01mailrc.txt.gz) time out.  This happens in 2 out of the 3 machines
I've tried it on, all of which live in the same LAN and behind the
same firewall.  I can't figure out why cpan works in one of the
machines but not in the others.  The two "failing machines" are
entirely different (a SuSE Linux box and an iMac).  The machine
where cpan works is another SuSE Linux box.

More confusingly still, I can download 01mailrc.txt.gz from the
"failing machines" if I use wget, which rules out some major
connection problem.  Unfortunately, cpan does not emit any diagnostic
to explain why its attempts to download files time out.  Why would
cpan fail when wget succeeds on the same machine?

Thanks!

kj

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


------------------------------

Date: 27 Mar 2007 14:46:07 -0700
From: usenet@DavidFilmer.com
Subject: Re: Troubleshooting cpan
Message-Id: <1175031967.042276.109460@o5g2000hsb.googlegroups.com>

On Mar 27, 1:57 pm, kj <s...@987jk.com.invalid> wrote:

> More confusingly still, I can download 01mailrc.txt.gz from the
> "failing machines" if I use wget

But is your CPAN module configured to use wget as a communication
method?  (type 'o conf' in a CPAN shell and see if wget is correctly
defined)


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



------------------------------

Date: Tue, 27 Mar 2007 21:45:01 GMT
From: "BradenM - Sonoma Computer" <BradenM@SonomaComputer.com>
Subject: Writing a system log monitor
Message-Id: <xfgOh.19084$uo3.3815@newssvr14.news.prodigy.net>

Hello;
I posted earlier this week concerning a script that would take input and 
write it out to an email and came to the conclusion that it was far too 
complicated for my own knowledge. So, I've decided to use the File::Monitor 
module to watch and monitor log files on my OpenBSD system. My question is 
this, does this seem like a task that is easily understanable and worth 
undertaking for a Perl newbie or should I try something else?




------------------------------

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 274
**************************************


home help back first fref pref prev next nref lref last post