[28150] in Perl-Users-Digest
Perl-Users Digest, Issue: 9514 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 22 18:11:19 2006
Date: Sat, 22 Jul 2006 15:10:08 -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 Sat, 22 Jul 2006 Volume: 10 Number: 9514
Today's topics:
Re: search and replace in a binary file <rafalk@comcast.net>
Re: search and replace in a binary file <tadmc@augustmail.com>
Re: search and replace in a binary file <rafalk@comcast.net>
Re: search and replace in a binary file <hjp-usenet2@hjp.at>
Re: Trouble with parsing text file and grabbing values <donaldjones@gmail.com>
Re: What is a type error? <benjamin.franksen@bessy.de>
Re: Win32-Printer problem mgarrish@gmail.com
Re: Win32-Printer problem <jwp@ont.com>
Re: Win32-Printer problem mgarrish@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 22 Jul 2006 12:44:55 -0400
From: Rafal Konopka <rafalk@comcast.net>
Subject: Re: search and replace in a binary file
Message-Id: <qok4c256kgcfr3fg6ll1u3h3oklashf8mc@4ax.com>
On Sat, 22 Jul 2006 09:56:44 -0500, Tad McClellan
<tadmc@augustmail.com> wrote:
>Rafal Konopka <rafalk@comcast.net> wrote:
>>[...]
>If you read from one file, write to another file, and then rename
>the 2nd file, then it requires no trickery at all.
>
>Perl can do this for you, see "-i" in perlrun.pod and $^I in perlvar.pod,
>though you might have to figure out how to binmode() the ARGV and ARGVOUT
>filehandles.
>
>
>> &edit_up('myfile');
>
>
> edit_up('myfile');
>
>
>You should not use ampersands on subroutine calls unless you know what
>using ampersands on subroutine calls does, and what it does is what
>you want to do. See perlsub.pod.
>
I've been using them (ampersands) all my life :-), but I'll check out
perlsub.pod
>... but $/ is not used for input via read() anyway, so there is no
>need to set it to anything in particular.
OK
>> if (!-d $OUT) {mkdir($OUT,07770);}
> ^^^^^
> ^^^^^ those are some mighty
> ^^^^^ funny-looking permissions...
>
>
typo
>Did you try it with different lengths and experience a problem?
Yes, that's the issue. The moment I replaced 150 with 20, I couldn't
open the file in the application.
>You probably need to handle the case where your to-be-replaced value
>is broken across buffer boundaries...
Exactly!
>
>> $buf =~ s/\[150\]/[100]/g;
> ^^^^^^
>
>That search string looks suspiciously non-binary to me.
it's just an example. Some of the replacements will be ascii strings
(like the one above) and some will be binary characters (e.g
chr(176)). The file itself is a binary file.
So how do I go about replacing 1 character with, say two or two
character with 1?
Thanks for your suggestions.
Rafal
------------------------------
Date: Sat, 22 Jul 2006 13:38:31 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: search and replace in a binary file
Message-Id: <slrnec4s56.943.tadmc@magna.augustmail.com>
Rafal Konopka <rafalk@comcast.net> wrote:
> On Sat, 22 Jul 2006 09:56:44 -0500, Tad McClellan
><tadmc@augustmail.com> wrote:
>
>>Rafal Konopka <rafalk@comcast.net> wrote:
>>>[...]
>>If you read from one file, write to another file, and then rename
>>the 2nd file, then it requires no trickery at all.
>>Did you try it with different lengths and experience a problem?
>
> Yes, that's the issue.
Did perl make the different length changes or not?
> The moment I replaced 150 with 20, I couldn't
> open the file in the application.
^^^^^^^^^^^^^^^^^^
That does not answer the question above.
Can you see the changes with a file dump or binary editor?
>>You probably need to handle the case where your to-be-replaced value
>>is broken across buffer boundaries...
>
> Exactly!
You say that as if it was mentioned in your original, it wasn't, I
was just pointing out that you may have more than one problem to
work on.
> So how do I go about replacing 1 character with, say two or two
> character with 1?
I think you aleady know how, by outputting 2 characters instead
of 1.
My guess is that perl is making the changes that you need, but that
those changes are incompatible with your unnamed "application".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 22 Jul 2006 15:15:35 -0400
From: Rafal Konopka <rafalk@comcast.net>
Subject: Re: search and replace in a binary file
Message-Id: <0qt4c25njq7sj8cgr9gggk1d4usbppg2fj@4ax.com>
On Sat, 22 Jul 2006 13:38:31 -0500, Tad McClellan
<tadmc@augustmail.com> wrote:
>Rafal Konopka <rafalk@comcast.net> wrote:
>> On Sat, 22 Jul 2006 09:56:44 -0500, Tad McClellan
>><tadmc@augustmail.com> wrote:
>>
>>>Did you try it with different lengths and experience a problem?
>>
>> Yes, that's the issue.
>
>
>Did perl make the different length changes or not?
>
>
>> The moment I replaced 150 with 20, I couldn't
>> open the file in the application.
> ^^^^^^^^^^^^^^^^^^
>That does not answer the question above.
>
>Can you see the changes with a file dump or binary editor?
>
Yes, I can see the changes in the dump file
I really know nothing about binary files. Having tried the character
for character replacvement successfully, I tried asymmetric
replacemtns. While I could see them in the dump file, I could no
longer open the file in the application.
>I think you aleady know how, by outputting 2 characters instead
>of 1.
>My guess is that perl is making the changes that you need, but that
>those changes are incompatible with your unnamed "application".
Essentially, it all boils down to this: imagine I have to replace
"Jon" with "Jonathan" and conversely "William" with "Billy" in a Word
document? The straight-forward search and replace is not going to
work, so how do I do it?
Rafal
------------------------------
Date: Sat, 22 Jul 2006 21:21:16 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: search and replace in a binary file
Message-Id: <pan.2006.07.22.19.21.15.758801@hjp.at>
On Sat, 22 Jul 2006 12:44:55 -0400, Rafal Konopka wrote:
> it's just an example. Some of the replacements will be ascii strings
> (like the one above) and some will be binary characters (e.g
> chr(176)). The file itself is a binary file.
>
> So how do I go about replacing 1 character with, say two or two
> character with 1?
There is no general solution. You need to know the format of the file
and take care to preserve the format when making changes. For example,
many binary format use length fields. If you change the length of a
record, you have to update the length field, too. Some file formats also
use checksums to detect corruption - then you need to recompute the
checksum, too.
Many file formats are documented at http://www.wotsit.org/default.asp
If the file in question is in a proprietary format you may need to ask
the vendor for information or reverse engineer it.
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 22 Jul 2006 11:10:13 -0700
From: "DJ" <donaldjones@gmail.com>
Subject: Re: Trouble with parsing text file and grabbing values needed
Message-Id: <1153591813.831489.141670@m79g2000cwm.googlegroups.com>
Thanks much for all the responses, was able to get that data out the
way I want it. Setting up that hash was really nice because I can
choose what I want out of there at any time. One more challenge I'm
having is I want to be able to pull out any lines within each record
that match a certain pattern when one line contains a specific number
at a specific place and the next line has different specific number in
a specific place. Here is an example:
ZMTH 11/02/02 2 0102 156 156 11
ZMTH 11/02/02 2 0202 156 156 11
ZMTH 11/02/02 2 0302 156 156 22
ZMTH 11/02/02 2 0402 96 96 11
The above is normal output. Say this output changes to this:
ZMTH 11/02/02 2 0102 156 156 11
ZMTH 11/02/02 6 0202 156 156 11
ZMTH 11/02/02 9 0302 156 156 22
ZMTH 11/02/02 2 0402 96 96 11
The second line here has a "6" in the third column and the third line
has a "9" in the third column. I want to know every time this happens
where lines have the 6 immediately followed by a 9 and extract out the
values in each column and probably put into a hash for grabbing
specific output later on through the program. I'm still treating the
record delimiter as "\nTEST1:".
Thanks again!
------------------------------
Date: Sat, 22 Jul 2006 17:50:25 +0200
From: Benjamin Franksen <benjamin.franksen@bessy.de>
Subject: Re: What is a type error?
Message-Id: <e9thg1$1gkg$1@ulysses.news.tiscali.de>
Darren New wrote:
> Chris Smith wrote:
>> Specialized
>> language already exist that reliably (as in, all the time) move array
>> bounds checking to compile time;
>
> It sounds like this means the programmer has to code up what it means to
> index off an array, yes? Otherwise, I can't imagine how it would work.
>
> x := read_integer_from_stdin();
> write_to_stdout(myarray[x]);
>
> What does the programmer have to do to implement this semantic in the
> sort of language you're talking about? Surely something somewhere along
> the line has to "fail" (for some meaning of failure) at run-time, yes?
You should really take a look at Epigram. One of its main features is that
it makes it possible not only to statically /check/ invariants, but also
to /establish/ them.
In your example, of course the program has to check the integer at runtime.
However, in a dependent type system, the type of the value returned from
the check-function can very well indicate whether it passed the test (i.e.
being a valid index for myarray) or not.
Ben
------------------------------
Date: 22 Jul 2006 11:00:10 -0700
From: mgarrish@gmail.com
Subject: Re: Win32-Printer problem
Message-Id: <1153591210.812494.252710@b28g2000cwb.googlegroups.com>
Jerry Preston wrote:
> My program had been running fine on a XP Home system until I re-installed
> the printer drivers and software for an HP 1315. I removed ALL of the
> latest Perl system and re-installed it and again my programs will not print
> to the printer.
>
Does anything print to your printer? It seems unlikely that you have a
Perl problem if everything was running fine up until the reinstall, so
aside from reinstalling your whole OS I don't know that you'll get much
useful advice here.
Matt
------------------------------
Date: Sat, 22 Jul 2006 18:06:10 GMT
From: "Jerry Preston" <jwp@ont.com>
Subject: Re: Win32-Printer problem
Message-Id: <mOtwg.11158$2v.7588@newssvr25.news.prodigy.net>
Matt,
The printer works fine except for printing with Perl. I was hoping to find
another solution other than a complete reinstall.
Thanks,
Jerry
<mgarrish@gmail.com> wrote in message
news:1153591210.812494.252710@b28g2000cwb.googlegroups.com...
>
> Jerry Preston wrote:
>
>> My program had been running fine on a XP Home system until I re-installed
>> the printer drivers and software for an HP 1315. I removed ALL of the
>> latest Perl system and re-installed it and again my programs will not
>> print
>> to the printer.
>>
>
>
> Does anything print to your printer? It seems unlikely that you have a
> Perl problem if everything was running fine up until the reinstall, so
> aside from reinstalling your whole OS I don't know that you'll get much
> useful advice here.
>
> Matt
>
------------------------------
Date: 22 Jul 2006 11:27:11 -0700
From: mgarrish@gmail.com
Subject: Re: Win32-Printer problem
Message-Id: <1153592831.342007.284040@p79g2000cwp.googlegroups.com>
Jerry Preston wrote:
> <mgarrish@gmail.com> wrote in message
> news:1153591210.812494.252710@b28g2000cwb.googlegroups.com...
> >
> > Jerry Preston wrote:
> >
> >> My program had been running fine on a XP Home system until I re-installed
> >> the printer drivers and software for an HP 1315. I removed ALL of the
> >> latest Perl system and re-installed it and again my programs will not
> >> print
> >> to the printer.
> >>
> >
> >
> > Does anything print to your printer? It seems unlikely that you have a
> > Perl problem if everything was running fine up until the reinstall, so
> > aside from reinstalling your whole OS I don't know that you'll get much
> > useful advice here.
> >
> The printer works fine except for printing with Perl. I was hoping to find
> another solution other than a complete reinstall.
>
But assuming no changes to your perl code and the OS, same printer and
same drivers that were present when the code was working, you'll
hopefully understand that there's not much advice to be given.
The only thing I can think of, and it seems like a big stretch, is if
you didn't completely remove the Perl directory before reinstalling
there might still exist some dependency in the Win32-Printer module
that was broken from when you reinstalled the driver. In which case,
even though you reinstalled the module, the faulty dll might not have
been overwritten (I've had this happen for the DBD-ODBC drivers when
upgrading Perl, for example, because the dlls are often in use by the
OS and can't be removed until after rebooting).
Matt
------------------------------
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 V10 Issue 9514
***************************************