[12584] in Perl-Users-Digest
Perl-Users Digest, Issue: 6184 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 30 23:07:12 1999
Date: Wed, 30 Jun 99 20:00:16 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 30 Jun 1999 Volume: 8 Number: 6184
Today's topics:
$1 not defined after AND ? <pautler@hawaii.edu>
Re: admininterface (Martien Verbruggen)
Re: Apples and Oranges (doug edmunds)
Clueless and in need of help! (Harmanie)
Re: David J Pimlott/GB/ITEC/ICI is out of the office. (Filip M. Gieszczykiewicz)
Help w/perl script <achau@pacbell.net>
Re: Perl or PNP...which is better? (Matthew Bafford)
q qq or qw <cyberjeff@sprintmail.com>
returning a hash from a function <derek@realware.com.au>
Re: Robot email/poster for this group (John Stanley)
Re: Robot email/poster for this group (John Stanley)
sgid perl problems (SNAFU)
Re: sgid perl problems <jbaird@idirect.com>
Re: uninstalling perl on NT <rolm@my-deja.com>
Re: uninstalling perl on NT <rolm@my-deja.com>
Re: use of stat function in Sprite hugh.casey@colorado.edu
What is rally_results()??? <apeng@timecruiser.com>
Re: win32 file access flounder99@my-deja.com
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 30 Jun 1999 14:08:19 -1000
From: David Pautler <pautler@hawaii.edu>
Subject: $1 not defined after AND ?
Message-Id: <377AB173.BE03022F@hawaii.edu>
Perl.misc,
I've checked "Perl 5 Complete" and the Perl FAQ first, but can't find an
answer.
When such vars as $1 are bound in the first clause of a conjunction (AND
or &&), is the bound value accessible in the later clauses or only in
the 'then' part of the 'if' ?
For example, this fragment doesn't print anything,
while( ($page =~ s| "(http [^"]*? isbn \s* ~ \s* (\d+ X?) [^"]*? )" .*?
>(.*?)< ||six ) #){
and ($3 =~ m|$requested_title|six) ) {
print "ISBN = $ISBN\n" if $ISBN = $2;
print "Title = $found_title\n" if $found_title = $3;
print "$address\n" if $address = $1;
print "Matched.\n" if $3 =~ m|$requested_title|six;
print "\n";
}
but if it is replaced with this fragment, then the whole program prints
several matching titles:
my ($three);
while( ($page =~ s| "(http [^"]*? isbn \s* ~ \s* (\d+ X?) [^"]*? )" .*?
>(.*?) < ||six ) ){
$three = $3;
if ($three =~ m|$requested_title|six) {
print "Title = $found_title\n" if $found_title = $three;
print "\n";
}
}
btw, what is the standard term for such vars as $1, $2, etc?
-dp-
------------------------------
Date: Thu, 01 Jul 1999 02:42:34 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: admininterface
Message-Id: <uAAe3.91$gB2.6767@nsw.nnrp.telstra.net>
In article <7ldiqj$skk$1@news1.tele.dk>,
"Kenny Weng" <kenny@weng.dk> writes:
> How do I configure a script to run as root and
> write files as root, when running Apache as Nobody?
# perldoc perlsec
Martien
--
Martien Verbruggen |
Interactive Media Division | For heaven's sake, don't TRY to be
Commercial Dynamics Pty. Ltd. | cynical. It's perfectly easy to be
NSW, Australia | cynical.
------------------------------
Date: Thu, 01 Jul 1999 00:30:29 GMT
From: edmundsMUNGED@pacifierMUNGED.com (doug edmunds)
Subject: Re: Apples and Oranges
Message-Id: <377ab02c.25324711@news.pacifier.com>
On 30 Jun 1999 18:32:21 GMT, mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:
>
>And if you add the extra line to the end of your test
>
> print \$$t, \$1, \$2, "\n";
>
>you get the extra output (for example)
>
> SCALAR(0xb3e48)SCALAR(0xb3f08)SCALAR(0xb3f44)
>
>showing that $$t and $1 are *not* the same variable.
But they are both references to the same memory location.
#----code starts -------
$t = '1 orange';
$s = 'testing fruit';
$s =~ /.+(es).*(fr)/;
print "\ntesting: $$t, $1, $2\n";
#print \$$t, \$1, \$2, "\n";
print "match to \$1 \n";
print \$$t->[0], \$1->[0], \$2->[0], "\n";
print \$$t->[1], \$1->[1], \$2->[1], "\n";
#################
$t = '2 orange';
$s = 'testing fruit';
$s =~ /.+(es).*(fr)/;
print "\ntesting: $$t, $1, $2\n";
#print \$$t, \$1, \$2, "\n";
print "match to \$2 \n";
print \$$t->[0], \$1->[0], \$2->[0], "\n";
print \$$t->[1], \$1->[1], \$2->[1], "\n";
#################
$t = 'An orange';
$s = 'testing fruit';
$s =~ /.+(es).*(fr)/;
print "\ntesting: $$t, $1, $2\n";
#print \$$t, \$1, \$2, "\n";
print "No match \n";
print \$$t->[0], \$1->[0], \$2->[0], "\n";
print \$$t->[1], \$1->[1], \$2->[1], "\n";
#---- code ends --------
--- Doug Edmunds
------------------------------
Date: 01 Jul 1999 01:55:11 GMT
From: harmanie@aol.com (Harmanie)
Subject: Clueless and in need of help!
Message-Id: <19990630215511.23761.00004679@ng-cf1.aol.com>
I don't claim to know the first thing about perl except that it looks REALLY
confusing! Anyhow, I bought a little program thingy and can't for the life of
me figure out how to use it. Someone please take pity on me and help! It is a
greeting card script. These are my instructions:
# This file, is the only place where u will need to make changes
# unless, you don't like my html designs :(.
#
# After making them, run the acecard.pl from the operating system:
# %perl acecard.pl
#
# and all will be set for you.
# After setup, point your browser to: $html_url/$index_html
# that you will setup below.
Okay, I went through and setup everything that I think needs to be setup. I
know that perl is located on my server at /usr/bin/perl
I have uploaded all of the pl files to my cgi-bin
How in the heck to I run the acecard.pl from the operating system?
Go ahead and laugh...I have been skimming your posts and am perfectly willing
to accept that this is probably the stupidest question on this board, but I am
not going to be intimidated :) and more importantly I am DESPERATE! Thank you
in advance for having mercy on me!
Christine
------------------------------
Date: 1 Jul 1999 02:31:57 GMT
From: fmgst+@pitt.edu (Filip M. Gieszczykiewicz)
Subject: Re: David J Pimlott/GB/ITEC/ICI is out of the office.
Message-Id: <7lejut$dra$1@usenet01.srv.cis.pitt.edu>
In Article <slrn7ne617.v72.abigail@alexandra.delanet.com>, through puissant locution, abigail@delanet.com soliloquized:
[snip]
>perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
>0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
>=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
>!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
Dies with:
Bad name after lwe:: at p.pl line 1.
perl -V
Summary of my perl5 (5.0 patchlevel 4 subversion 1) configuration:
Platform:
osname=solaris, osvers=2.5.1, archname=sun4-solaris
uname='sunos ultra-red.cis.pitt.edu 5.5.1 generic_103640-05 sun4u sparc sunw,ultra-1 '
hint=recommended, useposix=true, d_sigaction=define
bincompat3=n useperlio= d_sfio=
Compiler:
cc='gcc', optimize='-O', gccversion=2.7.2.1
cppflags='-I/usr/pitt/include -I/usr/include/db -DDEBUGGING'
ccflags ='-I/usr/pitt/include -I/usr/include/db -DDEBUGGING'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, randbits=15
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/pitt/lib'
libpth=/usr/pitt/lib /lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt
libc=/lib/libc.so, so=so
useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
cccdlflags='-fPIC', lddlflags='-G -L/usr/pitt/lib'
Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING
Built under solaris
Compiled at Jun 23 1997 16:57:50
@INC:
/usr/pitt/lib/perl5
/usr/pitt/lib/perl
/usr/pitt/lib/perl
.
--
Filip "I'll buy a vowel" Gieszczykiewicz | http://www.repairfaq.org/
Always and everything for the better!
Now exploring whatever, life, and the meaning of it all... and 'not' :-)
------------------------------
Date: Wed, 30 Jun 1999 18:17:19 -0700
From: "Andy" <achau@pacbell.net>
Subject: Help w/perl script
Message-Id: <8mze3.725$mq2.57513@typhoon-sf.snfc21.pbi.net>
Hi,
I have a webpage with about 100+ thumbnail pics. They run vertically down
the left column of my framed page.
I need to randomize how these thumbnails appear. (so that the ones at the
end won't stay at the end). These thumbnails also have links to htm pages
that appear on the right frame of the page. I have found numerous scripts
that deal with banner or image rotations, but they don't allow all the
pictures to display randomly. Only one at a time. I have found the
following script:
#!/usr/bin/perl
$|=1;
$mypic[0]="/images/picture0.gif WIDTH=400 HEIGHT=40";
$myurl[0]="/index.shtml";
$mypic[1]="/images/picture1.gif WIDTH=400 HEIGHT=40";
$myurl[1]="/ssi.shtml";
$mypic[2]="/images/picture1.gif WIDTH=400 HEIGHT=40";
$myurl[2]="/recycle.shtml";
$mypic[3]="/images/picture3.gif WIDTH=400 HEIGHT=40";
$myurl[3]="/cgi.shtml";
srand(time ^ $$);
$pick = rand(@mypic);
print "Content-type: text/html\n\n";
print "<A HREF=\"$myurl[$pick]\"> <IMG SRC=$mypic[$pick]></A>"
This allows for 3 pictures to be randomly displayed, but one at a time, with
it associated link.
How can I modify this so that all the pictures (3) will display, but in
random order.
Also, is this the most efficient script to expand on...are there better
ones?
Thanks
Andy
achau@pacbell.net
------------------------------
Date: Thu, 01 Jul 1999 01:08:18 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Perl or PNP...which is better?
Message-Id: <slrn7nleas.1ho.*@dragons.duesouth.net>
Once upon a time (Tue, 29 Jun 1999 12:20:03 -0400), Tad McClellan) was
attempting to figure out Ilya's new Perl regex features, and accidently
sent the following to comp.lang.perl.misc:
: Daniel (danielrod@nts.co.jp) wrote:
: : am not a Perl programmer, and I am not a PNP programmer, which has the
: ^^^
: What is PNP?
PNP: Plug and Play (Pray)
A popular form of technology amongst Windows users, Plug and Play
is supposed to make installing new hardware easier. In reality,
however, most people have more problems with Plug and Play
devices (hence the Pray) than they do with more traditional
hardware. Plug and Play is barely supported under Linux.
Perl: Pathologically Eclectic Rubbish Lister
Once limited only to users on Unix type systems, this popular
programming language has been ported to a variety of operating
systems. With Perl's extensive use of non alphanumeric
characters, it is possible to type a random string and actually
get a working program. Because of it's wider OS coverage and the
greater success rate of totally random configurations, it has
often been suggested that new hardware speak Perl rather than
PNP.
HTH!
--Matthew
------------------------------
Date: Wed, 30 Jun 1999 22:45:00 -0400
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: q qq or qw
Message-Id: <377AD62C.24BBEA9C@sprintmail.com>
What is the difference between using:
q{}
qq{}
qw{} ???
I've seen them all used.
Jeff
------------------------------
Date: Thu, 01 Jul 1999 10:58:44 +1000
From: Derek Lavine <derek@realware.com.au>
Subject: returning a hash from a function
Message-Id: <377ABD42.73F0F614@realware.com.au>
I have a problem with returning a hash from a function of an object.
I want to say something like
use strict;
...
my %hash = $obj->get_hash_func;
foreach $key (keys %hash ) {
print "$key => %hash->{$key} \n";
}
but this does not work, the get_hash_func looks like this and it is in
the object .pm file
sub get_hash_func {
my ($self) = @_;
return %$self->{"varialbles"};
}
I do not know if I am returning the hash from the function incorrectly
or trying to access the values in %hash incorrectly or if the assignment
of %hash = $obj->get_hash_func; is incorrect
has anyone any ideas.
I have also tried
my $hash;
$hash = $obj->get_hash_func;
thanks very much for your time
regards
derek
------------------------------
Date: 1 Jul 1999 00:28:39 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Robot email/poster for this group
Message-Id: <7lecnn$o37$1@news.NERO.NET>
In article <a1so79eawn.fsf@cyclone.jprc.com>,
Jason Reed <jcreed@cyclone.jprc.com> wrote:
>Well, not all of what actually occurs on c.l.p.m is useful discussion.
There's a stop sign on the corner of my street.
Not everybody stops at the stop sign.
Thus the stop sign isn't really a stop sign.
Define "useful". Maybe not useful to you, but useful to those who are
participating in them.
>> Assume for the sake of argument that the sun comes up in the west. Ok.
>
>I was just trying to describe an extreme, one endpoint on a continuum
>of bot effectiveness.
You were trying to describe a situation that will never exist. So was I.
I guess I wasn't clear about what I was trying to say.
>If the endpoint (perfect bot operation) is
>better than our current position on it (no bot at all), then maybe
But it is not. Your assumption that a robot is better than people
discussing things, in a USENET discussion group, is wrong.
>I'm not arguing that a decent bot is easy - but it might be feasible.
Of course it might be feasible. It won't be appropriate. The difference
is important.
Here. An example. It would be feasible for me to take a picture of the
coast of California, uuencode it, and post it to this group, once an
hour. It would not be appropriate. It IS appropriate on the web page
where this happens every day.
>Do you mean the relevant FAQ excerpts Tom posts so frequently in
>response to documented questions?
No, I mean the reposting of each and every FAQ section that Tom posts
here repeatedly. You certainly can't have missed them. They all start
with "FAQ:" in the subject. And the manpages that he also postes here
repeatedly. I forget what they start with.
>If they're never read, why does Tom post them?
I don't know. He's reposted the same things several times now.
>Should Tom be told not to post them, seeing as this is a discussion group?
You are free to try. The next time I see him flame a newbie for asking a
FAQ and he tells them that the FAQs are distributed with each copy of
perl, I was going to ask him why they were also being distributed here.
>I'm not arguing that a bot is definitely necessary - but it might be useful.
Sure. In the right venue. I say, give it an email address and let
people ask it questions all day long. And then, if it can't answer the
question, forward the question here. Just don't subject everyone who is
here to discuss things to a robot review of their articles. I don't want
a robot guessing at what my question is and trying to waste my time
sending me a copy of a FAQ that I already have here.
>> Why is it hard to understand the concept of communicating with a
>> robot via email instead of via a public discussion group?
>
>I thought you claimed email wasn't useful, since there would be no way
>for humans to know not to post anyway.
I didn't say email wasn't useful. I said if the robot answered questions
posted to the group by email, then nobody would know it was answering
and they would do it just like they always do.
If you COMMUNICATE with the robot by email, then you don't waste the
bandwidth distributing the request for the robot everywhere in the
world. You mail it the question, it mails you the answer. You get your
answer, and probably a lot faster than waiting for it to diffuse out via
news.
>Why is it hard to understand the concept of looking for documentation
>instead of asking for help via a public discussion group?
Do you find it hard? I don't. What does this have to do with a robot?
Should the fact that some people can't look things up mean that we all
should deal with a robot here? Should the fact that some people don't
stop at the stop sign mean we should all fail to stop at the stop
sign?
>> >So, in this utopia of strong AI, it's a *good thing*, isn't it?
>> No.
>
>Care to elaborate? Do you think it's a definite negative, or merely
>no better?
It is a good thing? No. It is not a good thing.
>Are you saying that, no matter how hard anyone tries, a bot will
>always produce more noise than any convenience it might produce, or,
>alternatively, that even if all of Tom's posts were coming from a bot,
>that would still be bad?
No matter how hard anyone tries, this will still be a discussion group.
>> Other people actually have to pay for transporting this stuff, and
>> piling it all into the group and telling them to killfile what
>> shouldn't be there in the first place is an insult.
>
>So does the volume of FAQs and answers (by humans) thereto bother you
>at all? (Should they '[not] be there in the first place'?)
Not as much as a robot. People discussing perl is what this group was
created for.
>Would it bother you more if those answers came from a bot instead,
>simply because bots-have-no-place-on-usenet?
Because it is a waste of a lot of bandwidth to use a USENET newsgroup
as a way of asking questions to a robot. Why should your question be
broadcast to sites all over the world when the only place it needs to
go is to the robot host? Why should the robot answer, if posted, be
broadcast all over the world when the only place it has to go is to
you?
------------------------------
Date: 1 Jul 1999 00:30:53 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Robot email/poster for this group
Message-Id: <7lecrt$o3k$1@news.NERO.NET>
In article <ylvhc55u7f.fsf@windlord.stanford.edu>,
Russ Allbery <rra@stanford.edu> wrote:
>John Stanley <stanley@skyking.OCE.ORST.EDU> writes:
>
>> No, the truth is I did post to the moderated group. Marcel just missed
>> it in all the FAQS and man page postings that make reading the moderated
>> group impossible.
>
>There's a FAQ posted to the moderated group, but the only man page
>postings I'm aware of are the ones that Tom's posting to this group.
>They're not in the moderated group (nor do I think they'd be appropriate
>for it).
That was sarcasm. I know there aren't a lot of FAQs and manpages posted
to the moderated group. I read it several times a day. I was just giving
him the standard excuse for not having seen it.
------------------------------
Date: 30 Jun 1999 19:01:24 -0600
From: sfreed@swcp.com (SNAFU)
Subject: sgid perl problems
Message-Id: <7leel4$1t2@llama.swcp.com>
When I run a sgid script of mine that attempts to determine the
hostname of the current machine (using the Sys::Hostname hostname()
function), I get the following error message:
"Cannot get host name of local machine."
This error does not occur when I run the script as root...it only happens
when I attempt to run it as myself. I'm not sure what's going on
here...hostname() appears to work in every other situation. Does anyone
have any suggestions?
I am using version 5.005_02 built for i386-bsdos.
The script uses "#!/usr/bin/suidperl -T" and its permissions are 2755, and
chowned root.kmem.
In addition to posting them to this group, please e-mail them to me at:
josh@gilasoft.com. Thanks! :-)
Joshua Arnold
Magic Software Development
------------------------------
Date: Wed, 30 Jun 1999 21:29:59 -0400
From: John Baird <jbaird@idirect.com>
Subject: Re: sgid perl problems
Message-Id: <377AC496.53B52D43@idirect.com>
hello,
here is a simple little work around...
chances are you have already thought of it... but incase you have not here it
is:
cat /etc/hostname > temp.file
the cat cmd displays the contents of a file, and in this case we are using a
standard redirector to a file named temp.file
simple but effective...
regards,
Jonathan Baird
Telecommunications Analyst
SNAFU wrote:
> When I run a sgid script of mine that attempts to determine the
> hostname of the current machine (using the Sys::Hostname hostname()
> function), I get the following error message:
>
> "Cannot get host name of local machine."
>
> This error does not occur when I run the script as root...it only happens
> when I attempt to run it as myself. I'm not sure what's going on
> here...hostname() appears to work in every other situation. Does anyone
> have any suggestions?
>
> I am using version 5.005_02 built for i386-bsdos.
> The script uses "#!/usr/bin/suidperl -T" and its permissions are 2755, and
> chowned root.kmem.
>
> In addition to posting them to this group, please e-mail them to me at:
> josh@gilasoft.com. Thanks! :-)
>
> Joshua Arnold
> Magic Software Development
------------------------------
Date: Thu, 01 Jul 1999 00:19:56 GMT
From: RoLm <rolm@my-deja.com>
Subject: Re: uninstalling perl on NT
Message-Id: <7lec73$ufu$1@nnrp1.deja.com>
In article <377a8667.13296946@news.brandx.net>,
doran@NOSPAMrbj.com (Doran) wrote:
> I've inherited an NT webserver. It seems that several versions of Perl
> have been installed onto it over time, into several directories. I'd
> like to uninstall all versions completely and then reinstall one
> version from scratch.
>
> Do you 'spose it's okay for me to just delete all the files and then
> reboot and reinstall the current version, or should I go looking about
> in the registry for things to remove and/or edit? I figure that since
> I'm reinstalling it, any registry entries will be overwritten with
> correct values, but I'm not sure.
unless you absolutely, positively know what you are doing, editing the
registry could be crippling to your machine. just the same, deleting
the old installs, leaving the registry alone, and reinstalling Perl
could leave some loose ends in your registry that could hamper the
performance of your server.
(by no means am i an NT wizard but..) i suggest you try to use the
"Add/Remove Programs" control panel to get rid of the old versions
first. If that fails, don't delete the directories yet! you may loose
any uninstall information they contain that could be used by a thrid
party utility. lastly, install your new version of perl.
if you have the luxury to do so, reinstall NT and build the server from
scratch. that way you'll have no worries about what's in there.
oh yeah, document what you did for the next poor soul that comes along.
Ciao,
Rolm
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 01 Jul 1999 00:22:33 GMT
From: RoLm <rolm@my-deja.com>
Subject: Re: uninstalling perl on NT
Message-Id: <7lecbv$ui7$1@nnrp1.deja.com>
i forgot to mention that you might try posting to
microsoft.public.windowsnt.setup.
RoLm
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 01 Jul 1999 00:12:19 GMT
From: hugh.casey@colorado.edu
Subject: Re: use of stat function in Sprite
Message-Id: <7lebor$ubr$1@nnrp1.deja.com>
Never mind; I found the answer myself.
The book "Perl Cookbook" from O'Reilly much recommended!
--rick casey
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 30 Jun 1999 20:37:57 EDT
From: Alex Peng <apeng@timecruiser.com>
Subject: What is rally_results()???
Message-Id: <7led95$19tu$1@earth.superlink.net>
Hi,
I have read an example how to test web performance in Web Techniques.
I am so interested this sample and I try to duplicate it.
However, I can't pass tow thing in my Linux.
1, How to install Time::HiRes?
Since there is no installation instruction.
I try perl Makefile.PL
then, make but fail.
2, What is rally_results?
You can find the sample at
http://www.webtechniques.com/cgi-bin/sourcecode/1999/07/webm/2.lst
Thanks,
Alex
------------------------------
Date: Thu, 01 Jul 1999 01:14:07 GMT
From: flounder99@my-deja.com
Subject: Re: win32 file access
Message-Id: <7lefco$vhk$1@nnrp1.deja.com>
In article <377A18DF.BA1F37F0@mratings.com>,
Kenneth Massey <kmassey@mratings.com> wrote:
> That works great, but I need to actually replace an entry in
"file.txt",
> rather than just append to it. If I call
> open(FILE, ">$filename")
> then this will delete the file before it checks to see if it has
> been locked by someone else. (I did an experiment to verify this)
>
> So my problem is that I have a list of names/emails/settings
> People login and change their settings, which I must replace in
> "list.txt".
> My plan was to
> 1) open "list.txt" and read the whole file into an array
> 2) open ">list.txt" and write the array back out, with the modified
> entry
>
> This doesn't seem appealing to me, especially if the file contains
many
> entries.
> Any ideas? Thanks,
>
> Kenneth
>
<Snip>
you don't want to close and reopen the file or some other program
(or program instance) may alter the file between the close and open.
the safe(er) way
open the file for append
lock the file using flock
seek the beginning of the file
read the data into an array
manipulate the array
seek back to the beginning of the file
use truncate() to shorten the file to 0
rewrite the data to the file
release the lock
this way you have exclusively locked the file
and other instances that use flock will wait
until you are done.
remember flock is only advisory, programs that
do not use it can still screw things up, so
always use it in all programs when more than
one of the programs (or instance of the same
program) might be altering the same file.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 6184
**************************************