[18260] in Perl-Users-Digest
Perl-Users Digest, Issue: 428 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 6 14:10:45 2001
Date: Tue, 6 Mar 2001 11:10:22 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983905822-v10-i428@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 6 Mar 2001 Volume: 10 Number: 428
Today's topics:
Re: pi day <joe+usenet@sunstarsys.com>
Re: Regex problem with array ul141@victoria.tc.ca
Re: Regex problem with array ul141@victoria.tc.ca
Re: RFC: FAQ3 update -- Using less memory <mjcarman@home.com>
Re: RFC: FAQ3 update -- Using less memory (Malcolm Dew-Jones)
Re: RFC: FAQ3 update -- Using less memory <joe+usenet@sunstarsys.com>
Re: statement for(list); <iltzu@sci.invalid>
Re: statement for(list); (Randal L. Schwartz)
Tk Newbie need Tk strategy help for updating image in c <eric.kort@vai.org>
Re: USING SEVERAL TIMES: $query -> param ('blah') =~ /^ nobull@mail.com
Re: USING SEVERAL TIMES: $query -> param ('blah') =~ /^ <mkuin@globalrangers.com>
USING SEVERAL TIMES: $query -> param ('blah') =~ /^([\d (EED)
What's wrong with (remedial)... <centreman_19@yahoo.com>
Re: What's wrong with (remedial)... (Peter L. Berghold)
Writing to the middle of a binary file <T.Goldfield@ftel.co.uk>
Re: Writing to the middle of a binary file nobull@mail.com
Re: Writing to the middle of a binary file <pkrupa@redwood.rsc.raytheon.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 06 Mar 2001 13:27:39 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: pi day
Message-Id: <sZ9p6.3060$L67.51319@news1.atl>
tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:
> I was shocked! How could Russ Jones <russ_jones@rac.ray.com>
> say such a terrible thing:
>
> >Coincidence? None of these has anything to do with Perl or pi, but I
> >really would like to get some Perl versions of pi calculations, the
> >more screwy the better. Anno's already suggested the "dropping
> >buckshot onto a circle" method.
>
> Can I just say, that method sucks. I remember doing that for a class in
> Numerical Analysis once. I seem to recall having to do 1000000
> iterations to get something like 3dp.
Would that be the O(N^1/2) convergence of typical Monte Carlo methods
that you are vaguely remembering?
> Well then why not turn this method around? Imagine drawing a large
> circle, measure it's circumference (in pixels) and then divide this by
> the diameter. Keep expanding the circle till you get sufficient
> accuracy.
^^^^^^^^
Accuracy != precision.
> This doesn't seem to converge though. Anyone have any idea why?
Sure it does. But not to pi.
[...]
> while ($x < $y)
> {
> if ($d < 0)
> {
> $d += 4 * $x + 6;
> }
> else
> {
> $d += 4 * ($x - $y) + 10;
> $y = $y - 1;
>
> $pixels += 0.5;
^^^^^^^^^^^^^^
What's half a pixel worth? Smells like the ghost of a departed
quantity - possibly an attempt to weight certain pixels more than others?
If you comment this fudge factor out, your algorithm should converge
( at O(N) ) to 2*sqrt(2). If circles were squares, this would be an
accurate value of pi.
> }
> $x = $x + 1;
>
> $pixels++;
> }
[...]
What you are doing is computing arclength,
and the formula for it is
2 2 2
ds = dx + dy
since dx=1, your loop should look like this instead:
while ($x < $y)
{
if ($d < 0)
{
$d += 4 * $x + 6;
}
else
{
$d += 4 * ($x - $y) + 10;
$y = $y - 1;
}
$length += $radius / sqrt( ($radius - $x) * ($radius + $x) );
$x = $x + 1;
}
$length/$radius should converge linearly to pi/4, since it's basically a
(left-endpoint) Riemann sum. If you want exponential convergence, see
google(ramanujan sum pi), or ask in a more appropriate newsgroup.
--
Joe Schaefer "Sometimes one pays most for the things one gets for nothing."
--Albert Einstein
------------------------------
Date: Tue, 06 Mar 2001 08:58:49 -0800
From: ul141@victoria.tc.ca
Subject: Re: Regex problem with array
Message-Id: <ul141-0603010858500001@10.10.10.2>
In article <%G%o6.484$642.27140@news2.atl>, Joe Schaefer
<joe+usenet@sunstarsys.com> wrote:
> ul141@victoria.tc.ca writes:
> I think you want to quote the metacharacters in a string
> that winds up in a regexp. Did you check
>
> % perldoc -q quote
>
> already?
. . . no, but thanks for the tip. Told you I was new :)
> > Backslashing the bracket in the string doesn't seem to help . . .
>
> Why not?
. . . because I'm an idiot? ;) It does indeed work. I had tried using both
single and double quotes around each string, but I had only tried escaping
the metacharacter with a single slash in double quotes.
> However, since you're just checking for a substring match,
> why not just use index ( perldoc -f index ) and avoid the
> escaping issue?
. . . I will take a look at that next, thanks :) For now, my code is
working and I'm a happy camper . . .
Glenn
------------------------------
Date: Tue, 06 Mar 2001 09:00:05 -0800
From: ul141@victoria.tc.ca
Subject: Re: Regex problem with array
Message-Id: <ul141-0603010900050001@10.10.10.2>
In article <c919at4u1lhijj43fk47ljsgt44judfeq1@4ax.com>, Jay Tilton
<nouser@emailunwelcome.com> wrote:
> ul141@victoria.tc.ca wrote:
>
> >below tries to grep @thatArray, I get an unmatched () error. The second
> >member of @thisArray has a forward bracket as part of the string, which is
> >causing the problem I know, but how to get around it?
>
> The easy way is to use metaquote, \Q, in the regex.
(snip)
. . . thanks, I'm learning plenty here ;)
Glenn
------------------------------
Date: Tue, 06 Mar 2001 11:09:51 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <3AA519DF.38ACCB30@home.com>
Ilya Zakharevich wrote:
>
> Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
>
>> ! Don't make anything global that doesn't have to be. Use my()
>> ! prodigiously to localize variables to the smallest possible scope.
>> ! Memory freed by variables that have gone out of scope can be reused
>> ! elsewhere in the current program, preventing the need for additional
>> ! allocations from system memory.
>
> This ignores the fact that memory used by locals *is* reused, but one
> used by lexicals *is not*.
Whoa there! That's news to me.
So if I do this:
SOME_BLOCK: {
my @array = (0 .. 1000);
# ...
}
and no references to @array exist outside the block, the memory
allocated to it still won't be freed up for use elsewhere in the program
after I leave the block?
> But I'm not surprized. Perl's FAQ is much more a political document
> than a reliable document....
Apparently, because I've read that memory is reused in other parts of
the FAQ. I thought that I'd seen it elsewhere as well, but as I can't
find a book reference to it right now I may just be recalling reading it
here.
If this is true, then I want to strike that addition. (Okay, Chris?)
Localizing is still good advice, of course, but I'd hate to recommend it
for reasons that are inaccurate.
Side note: Admittedly, my "Pass by reference" addition is a little fuzzy
as well, but I was trying to keep things fairly short and didn't want to
get into all the details and subtle points.
-mjc
------------------------------
Date: 6 Mar 2001 09:41:59 -0800
From: yf110@victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <3aa52167@news.victoria.tc.ca>
Ilya Zakharevich (ilya@math.ohio-state.edu) wrote:
: [A complimentary Cc of this posting was sent to Chris Fedde
: <cfedde@fedde.littleton.co.us>],
: who wrote in article <1kSo6.389$T3.189894656@news.frii.net>:
: > ! Don't make anything global that doesn't have to be. Use my()
: > ! prodigiously to localize variables to the smallest possible scope.
: > ! Memory freed by variables that have gone out of scope can be reused
: > ! elsewhere in the current program, preventing the need for additional
: > ! allocations from system memory.
: This ignores the fact that memory used by locals *is* reused, but one
: used by lexicals *is not*.
: But I'm not surprized. Perl's FAQ is much more a political document
: than a reliable document....
On the issue of memory, you should be careful when using map or grep.
This may not be a problem anymore, but in earlier versions (probably 5.003
or 5.004), it appeared that map and grep would potentially cause an entire
file to be slurped.
I forget the exact reason I tested this and the exact syntax of my tests,
but from memory they were similar to these examples
-1- @lines_wanted = grep {m/whatever/} <FILE> ;
-2- while (<FILE>) { push @lines_wanted , $_ if m/whatever/ }
I could bring my machine to a grinding halt by running -1- on very large
files. It appeared from the OS memory stats that the entire file must
have been slurped. -2- had no such problem.
This was probably on 5.003 or 5.004.
------------------------------
Date: 06 Mar 2001 12:43:02 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: RFC: FAQ3 update -- Using less memory
Message-Id: <Fj9p6.3045$L67.50180@news1.atl>
[ This is a repost of a followup I posted yesterday that seems to
have been lost. Apologies if you've read the original. ]
Michael Carman <mjcarman@home.com> writes:
[...]
>
> =item * Don't slurp!
>
> Don't read an entire file into memory if you can process it line
> by line. Whenever possible, use this:
>
> while (<FILE>) {
> # ...
> }
>
> instead of this:
>
> @data = <FILE>;
> foreach (@data) {
> # ...
> }
and B<never> use this:
for (<FILE>) {
# ...
}
[...]
> =item * Localize!
>
> Don't make anything global that doesn't have to be. Use my() prodigously
> to localize variables to the smallest possible scope. Memory freed by
> variables that have gone out of scope can be reused elsewhere,
> preventing the need for additional allocations.
=item * Avoid unnecessary quotes and stringification
Don't use quote large strings unless absolutely necessary:
my $copy = "$large_string";
makes 2 copies of $large_string (one for $copy and another for
the quotes), whereas
my $copy = $large_string;
only makes one copy.
Ditto for stringifying large arrays:
{
local $, = "\n";
print @big_array;
}
is much more memory-efficient than either
print join "\n", @big_array;
or
{
local $" = "\n";
print "@big_array";
}
If you need to initialize a large variable in your code, you
might consider doing it with an eval statement like this:
my $large_string = eval ' "a" x 5_000_000 ';
This allows perl to immediately free the memory allocated to the
eval statement, but carries a (small) performance penalty.
> =item * Pass by reference
>
> Pass arrays and hashes by reference, not by value. For one thing, it's
> the only way
(sans prototyping)
> to pass multiple lists or hashes (or both) in a single call/return. It
> also avoids creating a copy of all the contents.
<correction>
Array elements are passed by reference, not copied (like hash entries
are). The differences between
(A) foo(\@array)
and
(B) foo(@array)
are
1> (A) avoids (B)'s overhead of setting up the aliases in @_,
2> (A) can manipulate @array itself, (e.g. push, pop, $#array, etc.),
whereas (B) can only modify the values of the elements in @array.
There's probably more, that's all I can think of off the top of my head.
I think you should rework this section a bit.
</correction>
> This requires some judgement, however, because any changes will be
> propagated back to the original data. If you really want to mangle
> (er, modify) a copy, you'll have to sacrifice the memory needed to
> make one.
... If your copy consumes a large amount of RAM, you may want
to explicitly undef() your copy once you are no longer need it. Perl
might then return the additional memory back to the OS.
[...]
Otherwise it looks good to me.
HTH
--
Joe Schaefer "Not everything that counts can be counted, and not everything
that can be counted counts."
--Albert Einstein
------------------------------
Date: 6 Mar 2001 16:12:07 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: statement for(list);
Message-Id: <983893350.4701@itz.pp.sci.fi>
In article <slrn9a99ru.efn.mgjv@martien.heliotrope.home>, Martien Verbruggen wrote:
>On 5 Mar 2001 16:31:48 GMT,
> Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>>
>> This is not how Perl's syntax is defined. One can define the same
>> precedence for these operators and left associativity. Is this what
>> you have in mind?
>
>Yes. Although I can't immediately see whether that would allow what I
>want. Precedence would have to be low, maybe just below list ops..... or
>maybe just above comma and =>. Somewhere around there anyway.
I think there was a thread about this before.. right, see my post
<979385947.18000@itz.pp.sci.fi>, originally proposing "then" as a
low-precedence (below "or") equivalent of the scalar comma:
This would tie in with another item on my wish list, stacked statement
modifiers:
print if /foo/ while <>;
Or maybe we could generalize statement modifiers to expression
modifiers (I'd let if / unless return () or undef if false, and while
/ for could return their last value, or () / undef for cases of zero
iterations) and then dispense with the concept of statements entirely.
That would make ";" and my proposed "then" essentially equivalent,
except for their precedence relative to statement -- oops, expression
-- modifiers. We'd need to rethink the concept of blocks, though.
Maybe they could be just a variation of parentheses that creates a new
scope.. That'd push TIMTOWTDI to a whole new level.
I still think that would be cool.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"So if you were shot with a .38, the homeopathic treatment is probably to
deal with the remaining problem with a .22." -- Zed Pobre in the SDM
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: 06 Mar 2001 09:10:46 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: statement for(list);
Message-Id: <m1snkq7rhl.fsf@halfdome.holdit.com>
>>>>> "Ilmari" == Ilmari Karonen <iltzu@sci.invalid> writes:
Ilmari> This would tie in with another item on my wish list, stacked
Ilmari> statement modifiers:
Ilmari> print if /foo/ while <>;
Ilmari> Or maybe we could generalize statement modifiers to
Ilmari> expression modifiers (I'd let if / unless return () or undef
Ilmari> if false, and while / for could return their last value, or
Ilmari> () / undef for cases of zero iterations) and then dispense
Ilmari> with the concept of statements entirely.
Ilmari> That would make ";" and my proposed "then" essentially
Ilmari> equivalent, except for their precedence relative to
Ilmari> statement -- oops, expression -- modifiers. We'd need to
Ilmari> rethink the concept of blocks, though. Maybe they could be
Ilmari> just a variation of parentheses that creates a new scope..
Ilmari> That'd push TIMTOWTDI to a whole new level.
Ilmari> I still think that would be cool.
I asked Larry about this back in the "early days". He added this
based on his experience with BASIC-PLUS on RSTS/E systems (which I'm
also familiar with). When I asked him why he didn't permit nested
modifiers as in BASIC+, he said (and I concurred) that there was *far*
too much abuse of that in BASIC+ programs, making the programs read
unnaturally. So he deliberately limited it to a simple expression
modifying another simple expression for readability. If you want
nesting, use the forward-reading block forms instead.
So, unless Larry's changed his mind (rule #2), we won't have nested
modifiers (rule #1). And so far, I agree with his original
conclusion.
print "Just another Perl hacker,";
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 6 Mar 2001 09:45:59 -0500
From: "Eric" <eric.kort@vai.org>
Subject: Tk Newbie need Tk strategy help for updating image in canvas
Message-Id: <982stg$s6o$1@msunews.cl.msu.edu>
Greetings. First of all, can someone on comp.lang.perl.tk point me to the
FAQ for comp.lang.perl.tk?
Now my question, and apologies if this is in the FAQ. I have developed some
microscopy image analysis software in perl, and now I am working on the user
interface. I wonder if someone can point me in the right direction for
dynamically updating the displayed image like so:
I have created a canvas widget to display the image (using Tk::TIFF). But I
want to allow the user to set a threshold, and to visualize the threshold by
turning all pixels below the threshold some color (say, blue). So I plan to
use the Scale widget to get the threshold level. But once I get the
threshold, how do you recommend I update the image (a la Gimp after you make
some image adjustment)? Here are some ideas I had:
1. I could create a new temproary tiff with the pixels below threshold
recolored, and then reload the new tiff from file into the canvas. But this
seems like it would be terribly slow.
2. I could convert the tiff to a bitmap, modify the bitmap, and update the
canvas object. I have written a perl module which gives me the Tiff image
data as an array of pixel intensities (libtiff does this as well), and it
appears from the documentation that I could convert it to X11 bitmap format
and use the -data => $string option? If that's right, can someone point me
to documentation on the X11 bitmap format?
Thanks for your help,
Eric
------------------------------
Date: 06 Mar 2001 17:46:24 +0000
From: nobull@mail.com
Subject: Re: USING SEVERAL TIMES: $query -> param ('blah') =~ /^([\d.]+)$/ ? $1 : 'null'
Message-Id: <u9vgpmn633.fsf@wcl-l.bham.ac.uk>
"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
> printf $UPDCNT,
> ($query -> param ('EXTERN') =~ /^([\d.]+)$/ ? $1 : 'null'),
> ($query -> param ('INVEST') =~ /^([\d.]+)$/ ? $1 : 'null');
Change $1 to "$1".
print ( 'foo'=~/(.*)/ ? $1 : '', 'bar'=~/(.*)/ ? $1 : ''); # barbar
print ( 'foo'=~/(.*)/ ? "$1" : '', 'bar'=~/(.*)/ ? "$1" : ''); # foobar
Perhaps when the FAQ says quoting variables is wrong 99.8% of the time
it should explain the 0.2%
This is the second unrelated question I've answered today to which the
answer is to quote a variable.
Of course, in the original question, I'd have used map() and never
encoutered the problem.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 6 Mar 2001 17:29:13 +0100
From: "Mark Kuin" <mkuin@globalrangers.com>
Subject: Re: USING SEVERAL TIMES: $query -> param ('blah') =~ /^([\d.]+)$/ ? $1 : 'null'
Message-Id: <9833kk$ea2$1@news1.xs4all.nl>
> printf $UPDCNT,
> $dbh -> quote ($query -> param ('ASO')),
> $quarter,
> $year,
> ($query -> param ('TOTHEAD') =~ /^([\d.]+)$/ ? $1 : 'null'),
> ($query -> param ('EFFHEAD') =~ /^([\d.]+)$/ ? $1 : 'null'),
> ($query -> param ('EXTERN') =~ /^([\d.]+)$/ ? $1 : 'null'),
> ($query -> param ('INVEST') =~ /^([\d.]+)$/ ? $1 : 'null');
You should use temporary variables which are less temporary then $1.....
my $tmp_1 = $query -> param ('TOTHEAD');
$tmp_1 =~ /^([\d.]+)$/ ? $1 : 'null';
my $tmp_2 = $query -> param ('EFFHEAD');
$tmp_2 =~ /^([\d.]+)$/ ? $1 : 'null';
my $tmp_3 = $query -> param ('EXTERN');
$tmp_3 =~ /^([\d.]+)$/ ? $1 : 'null';
my $tmp_4 =$query -> param ('INVEST');
$tmp_4 =~ /^([\d.]+)$/ ? $1 : 'null');
printf $UPDCNT,
$dbh -> quote ($query -> param ('ASO')),
$quarter,
$year,
$tmp_1,
$tmp_2,
$tmp_3,
$tmp_4;
------------------------------
Date: Tue, 06 Mar 2001 17:11:40 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: USING SEVERAL TIMES: $query -> param ('blah') =~ /^([\d.]+)$/ ? $1 : 'null'
Message-Id: <3AA50C3C.B21C321E@eed.ericsson.se>
Hi,
I have 4 text fields and would like to compose an SQL-statement:
$UPDCNT = 'insert_update_heads %s, %d, %d, %f, %f, %f, %f';
printf $UPDCNT,
$dbh -> quote ($query -> param ('ASO')),
$quarter,
$year,
($query -> param ('TOTHEAD') =~ /^([\d.]+)$/ ? $1 : 'null'),
($query -> param ('EFFHEAD') =~ /^([\d.]+)$/ ? $1 : 'null'),
($query -> param ('EXTERN') =~ /^([\d.]+)$/ ? $1 : 'null'),
($query -> param ('INVEST') =~ /^([\d.]+)$/ ? $1 : 'null');
However I get this output:
insert_update_heads 'aso1', 1, 2001, 4.000000, 4.000000, 4.000000, 4.000000
Even though I have entered: 1, 2, 3, 4
into the corresponding text fields... Does someone see what am
I doing wrong above? Why is only the last value (the 4) used?
Thank you
Alex
------------------------------
Date: Tue, 6 Mar 2001 10:28:15 -0800
From: "Brandon Thornburg" <centreman_19@yahoo.com>
Subject: What's wrong with (remedial)...
Message-Id: <983adb$bva$1@fremont.ohsu.edu>
Ok, this should be ridiculously easy to figure out, but maybe there's
something about the OR statements I'm just missing. I'm just a beginner
here, folks.
if ($in{degree1} ne "B.S."||"B.A."||"A.A."||"A.S.") {
print STDOUT ", $in{degree1}";
}else{
print STDOUT "";
}
Now, I should say here that I've tried lots of different permutations of
this, including extra parentheses, leaving off the else statement, etc. and
yet somehow the first statement is always the one returned. (This is CGI, by
the way, so if there's a better newsgroup to post to please let me know).
------------------------------
Date: Tue, 06 Mar 2001 18:47:20 GMT
From: peter@uboat.berghold.net (Peter L. Berghold)
Subject: Re: What's wrong with (remedial)...
Message-Id: <slrn9aac5n.egn.peter@uboat.berghold.net>
On Tue, 6 Mar 2001 10:28:15 -0800,
Brandon Thornburg <centreman_19@yahoo.com> wrote:
>if ($in{degree1} ne "B.S."||"B.A."||"A.A."||"A.S.") {
That just plain ain't gonna work....
Try this instead:
my %degList = (
'B.S.' => 1,
'B.A.' => 1,
'A.A.' => 1,
'A.S.' => 1
);
if ( $degList{$in{$degree1}} ) {
--- whatever....
There are probably (no doubt) more clever ways of doing this, but that
is the first method that popped into my head....
--
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Peter L. Berghold Peter@Berghold.Net
"Linux renders ships http://www.berghold.net
NT renders ships useless...."
------------------------------
Date: Tue, 06 Mar 2001 16:13:12 +0000
From: Timothy Goldfield <T.Goldfield@ftel.co.uk>
Subject: Writing to the middle of a binary file
Message-Id: <3AA50C98.8B64CDA2@ftel.co.uk>
I'm doing a project in which I have to open a binary file locate a
specific number, convert that number and then save the changes. Is there
anyway to write to a binary file at a specific location and overwrite
anything that was previously in that position. If not is there a way to
remove a chunk from a binary file so as the data after the chunk buts up
against the data before the chunk and then slot the new data in at that
point?
--
Tim Goldfield
--
Fujitsu Telecommunications Europe Ltd.
Birmingham
------------------------------
Date: 06 Mar 2001 17:46:37 +0000
From: nobull@mail.com
Subject: Re: Writing to the middle of a binary file
Message-Id: <u9u256n62q.fsf@wcl-l.bham.ac.uk>
Timothy Goldfield <T.Goldfield@ftel.co.uk> writes:
> I'm doing a project in which I have to open a binary file locate a
> specific number, convert that number and then save the changes. Is there
> anyway to write to a binary file at a specific location and overwrite
> anything that was previously in that position.
seek and print.
> If not is there a way to
> remove a chunk from a binary file so as the data after the chunk buts up
> against the data before the chunk and then slot the new data in at that
> point?
There is no way to slide stuff up and down in a file. This is not a
Perl thing, it's a filesystem thing.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 06 Mar 2001 11:32:28 -0700
From: "Peter A. Krupa" <pkrupa@redwood.rsc.raytheon.com>
Subject: Re: Writing to the middle of a binary file
Message-Id: <3AA52D3C.FABC642D@redwood.rsc.raytheon.com>
From a Canonical List of One-Liners:
binary edit (careful!)
perl -i.bak -pe 's/Mozilla/Slopoke/g' /usr/local/bin/netscape
Go back and refamiliarize yourself with the -e, -i, and -p perl command line
options before attempting this...
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 428
**************************************