[17390] in Perl-Users-Digest
Perl-Users Digest, Issue: 4812 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 4 21:05:26 2000
Date: Sat, 4 Nov 2000 18:05:09 -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: <973389909-v9-i4812@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 4 Nov 2000 Volume: 9 Number: 4812
Today's topics:
Re: 1+(-1)=? can be 0 or 2, depending on context <joe+usenet@sunstarsys.com>
[OT] Tootsie pops (Was: Unix commands via perl?) (Jon Bell)
Re: [Q] Matching \0 (Ilya Zakharevich)
Re: [Q] Matching \0 <bart.lateur@skynet.be>
Re: [Q] Matching \0 <kj0@mailcity.com>
Re: About to slit my own throat (Gwyn Judd)
Re: About to slit my own throat (Anthony)
Re: About to slit my own throat (Anthony)
Re: About to slit my own throat (Anthony)
Re: About to slit my own throat (Tad McClellan)
Re: About to slit my own throat (Gwyn Judd)
Re: Building a Module on Server without Install.pm (Martien Verbruggen)
Re: Building a Module on Server without Install.pm <not.my.real.email@bellglobal.com>
Re: Building a Module on Server without Install.pm (Martien Verbruggen)
Re: Building a Module on Server without Install.pm <jeff@vpservices.com>
Re: Building a Module on Server without Install.pm (Tony L. Svanstrom)
Re: File locking <g.soper@soundhouse.co.uk>
Re: Freelance Programmer Needed <not.my.real.email@bellglobal.com>
Re: How to check passwd is correct? <flavell@mail.cern.ch>
Re: how to sort corresponding arrays? (Mark-Jason Dominus)
Re: how to sort corresponding arrays? (Tad McClellan)
kill on Win32 <billhess2000@home.com>
Re: Perl syntax and beyond (was: Re: Perl style and mod (Gwyn Judd)
Re: String manipulation?? (Martien Verbruggen)
Re: Unix commands via perl? (Gwyn Judd)
Re: Unix commands via perl? <flavell@mail.cern.ch>
Re: Weak References Was: Keeping a List of Objects (Anno Siegel)
Why would subs not get the right args? <jicman@cinops.xerox.com>
Re: Why would subs not get the right args? (Martien Verbruggen)
Re: Why would subs not get the right args? <jeff@vpservices.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 04 Nov 2000 20:58:36 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <m3g0l7w56b.fsf@mumonkan.sunstarsys.com>
Helmut.Richter@lrz-muenchen.de (Helmut Richter) writes:
> > Joe Schaefer <joe+usenet@sunstarsys.com> writes:
[...]
> >In terms of a black box - could you explain the purpose of your
> >parse_linear ($) sub? Is it intended to turn a "stringified" vector
> >into an array, something like
>
> >@vec = parse_linear("-x+y+3z"); # returns (-1, x, 1, y, 3, z) ?
>
> Right. And parse_linear("-x+y+3z-2y+x") returns (-1, y, 3, z)
>
> There is also an "unparse_linear" which makes again a string out of it.
>
Ok- now I understand a bit more about what you want to do. It's not
trivial due to the algebraic manipulations you need here. That's the
hard part!
Because split and join are such natural counterparts to
parse_linear and unparse_linear, perl makes translating between
your data representations very easy. But IMHO it's the algebra
and the inherent ambiguities in your data representation
that's causing your headaches. If we can get rid of the
ambiguities, perl's RE engine makes the hard part tractable too:
$_ = "1x+3y-2z+4y+2z-6x+8w";
1 while s{([+-]*\d+)([a-z]+) # get first term
(.*?) # nongreedy to avoid grabbing +-
([+-]*\d+)\2 # get matching term
}{ ($1 + $4) . "$2$3" }eox; # reduce !
print $_; # returns "-5x7y0z+8w"
TMTOWTDI, but that's how I'd do it (perhaps not the fastest solution,
but certainly short :) Cleaned up a bit, here's the code
sub reduce ($) {
$_ = shift;
y/+ //d; # drops + signs and any spaces
1 while s{(-*\d+)([a-z]+)(.*?)(-*\d+)\2}{ ($1 + $4) . "$2$3" }eo;
s/(^|[a-z]+)0[a-z]+/$1/go; # drop terms with coefficient = 0
return $_;
}
sub parse_linear ($) {
split /([a-z]+)/, reduce shift;
}
sub unparse_linear (@) {
$_ = reduce join '', @_;
s/([a-z]+)(\d+)/$1+$2/go; # sticks the + back in
return $_;
}
I think with some tinkering you'll be able to get this to work
in your code - HTH!
Best wishes.
--
Joe Schaefer
------------------------------
Date: Sun, 5 Nov 2000 00:22:02 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: [OT] Tootsie pops (Was: Unix commands via perl?)
Message-Id: <G3Izoq.n07@presby.edu>
In article <slrn90821t.h71.tjla@thislove.dyndns.org>,
Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>
>On behalf of all the mystified non-merkins: What's a tootsie-pop?
See http://www.tootsie-roll.com/products.html :-)
--
Jon Bell <jtbell@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
[ Questions about newsgroups? Visit http://www.geocities.com/nnqweb/ ]
[ or ask in news:news.newusers.questions ]
------------------------------
Date: 4 Nov 2000 23:21:52 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: [Q] Matching \0
Message-Id: <8u25mg$klv$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to kj0
<kj0@mailcity.com>],
who wrote in article <8u23dr$5jt$1@panix3.panix.com>:
> I have a null-terminated string (a la C) followed by garbage. I'd
> like to get rid of the garbage by using something like
>
> $C_string =~ s/\0.*$//;
>
> but it doesn't work (no match; garbage stays).
Sigh... Looks like my patch which fixed \0-in-a-regex got dropped...
Hmm, I do not see how it can be, the bug was with patterns involving
interpolation.
perl -wle "$_=qq(a\0b); s/\0.*$//; print length"
1
works OK. Hmm, did not you want to use s///s instead? And \z ?
Ilya
------------------------------
Date: Sat, 04 Nov 2000 23:31:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: [Q] Matching \0
Message-Id: <11790t02f8plbd21q98eqtjua0hvm3q6e5@4ax.com>
kj0 wrote:
> $C_string =~ s/\0.*$//;
>
>but it doesn't work (no match; garbage stays).
That is because . doesn't match a newline. So this will kill everything
from the first "\0" till and including the first newline.
The /s modifier will fix that.
$C_string =~ s/\0.*$//s;
--
Bart.
------------------------------
Date: 4 Nov 2000 19:50:01 -0500
From: kj0 <kj0@mailcity.com>
Subject: Re: [Q] Matching \0
Message-Id: <8u2arp$bet$1@panix3.panix.com>
Yep. Thank you all.
KJ
In <11790t02f8plbd21q98eqtjua0hvm3q6e5@4ax.com> Bart Lateur <bart.lateur@skynet.be> writes:
>kj0 wrote:
>> $C_string =~ s/\0.*$//;
>>
>>but it doesn't work (no match; garbage stays).
>That is because . doesn't match a newline. So this will kill everything
>from the first "\0" till and including the first newline.
>The /s modifier will fix that.
> $C_string =~ s/\0.*$//s;
>--
> Bart.
------------------------------
Date: Sat, 04 Nov 2000 23:54:26 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: About to slit my own throat
Message-Id: <slrn9098dg.kpd.tjla@thislove.dyndns.org>
I was shocked! How could Anthony <apsaffer@hotmail.com>
say such a terrible thing:
>Hello Everyone,
>I have written a CGI script in Perl and it just isn't working. This
>script needs to work by Monday or else I am going to get it in a bad
>way. Could someone take a look at the code below and tell me why it
>isn't working. Here are a few things to get you started:
I'm kind of torn here between telling you what you did wrong
(everything) or not telling you anything (because this looks like some
kind of automated spam service, or could be used as such). There is
actually not much you need to get it working, in a broken down, "please
crash my server" kind of way. Maybe you need to tell us a bit more about
what this service is about. And maybe you should read the FAQ.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
A formal parsing algorithm should not always be used.
-- D. Gries
------------------------------
Date: Sun, 05 Nov 2000 00:13:16 GMT
From: apsaffer@hotmail.com (Anthony)
Subject: Re: About to slit my own throat
Message-Id: <3a04a5fd.20418515@news.rectec.net>
No, it is NOT a spam generator. It is an anonymous email program made
for a legitimate organization that will not use it for spam.
------------------------------
Date: Sun, 05 Nov 2000 00:19:51 GMT
From: apsaffer@hotmail.com (Anthony)
Subject: Re: About to slit my own throat
Message-Id: <3a04a64f.20500257@news.rectec.net>
Well upon thinking about this program in the way you guys are seeing
it I suppose it COULD be used as a spam generation program. However,
I do want to point out that this is not the intended purpose of this
program. The intended purpose of the program was to allow certain
individuals (who will need to login to a secure, private website) to
send mail to anyone else without the need to worry about someone
finding out who they are. This activity is NOT for commercial purposes
but rather legitimate private purposes. The line at the bottom of the
script that informs the user of the anonymizer is specifically there
to enable me (or whoever else may be monitoring at the time) to track
and take action against anyone using it for spam or commercial
purposes.
If you will notice, the script also keeps a log of everything sent
through it (and I was going to add a function to log the users IP
address too) so that I can gather as much information as possible
about it's users. My thoughts on this were that even though the
script had an "authorized users" list it could still be misused.
So, and I do hope all the other folks who answered read this too,
while the script DOES appear to be a spam generator (though how much
damage could it do being that it only sends out one mail at a time??)
that is not it's intended purpose.
Thanks to those of you who offered help.
Sincerely,
Anthony Saffer
------------------------------
Date: Sun, 05 Nov 2000 00:21:44 GMT
From: apsaffer@hotmail.com (Anthony)
Subject: Re: About to slit my own throat
Message-Id: <3a04a7e7.20909009@news.rectec.net>
On Sat, 04 Nov 2000 22:29:19 GMT, ameen @ dausha . net (Ameen Dausha)
wrote:
>Everybody, look at the last lines. This is a spam generator and the
>URL it refers to does not exist.
Try http://supermailer.netfirms.com/anonmail.html . The script is
still under development so it's not live as index.html yet.
Anthony
------------------------------
Date: Sat, 4 Nov 2000 17:56:03 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: About to slit my own throat
Message-Id: <slrn909503.5tb.tadmc@magna.metronet.com>
On Sat, 04 Nov 2000 22:02:34 GMT, Anthony <apsaffer@hotmail.com> wrote:
>I have written a CGI script in Perl and it just isn't working.
What form of "isn't working" do you mean.
Makes no output. Makes too much output. Doesn't make enough output.
Does not run. Runs too long. Runs too short.
Makes incorrect output.
Fills log file with confusing messages.
Causes a core dump.
Makes smoke come out of the computers tiny little vents.
???
>This
>script needs to work by Monday or else I am going to get it in a bad
>way.
You are probably going to get it in a bad way then.
>#!/usr/local/bin/perl
You have three problems already.
#!/usr/local/bin/perl -wT
use strict;
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 05 Nov 2000 01:59:33 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: About to slit my own throat
Message-Id: <slrn909fo3.kpd.tjla@thislove.dyndns.org>
I was shocked! How could Anthony <apsaffer@hotmail.com>
say such a terrible thing:
>So, and I do hope all the other folks who answered read this too,
>while the script DOES appear to be a spam generator (though how much
>damage could it do being that it only sends out one mail at a time??)
>that is not it's intended purpose.
Well you really need to put in some kind of limitation mechanism
otherwise people will simply hammer the page with an automated script
sending out message after message. You also need to limit the size of
message that you will accept (and no, I don't think the current limit of
100Mb or more is really acceptable). Once you've done that, then it
starts to look less like something someone could use for spam. You have
to realise that if something can be abused, it will be, therefore there
is no point saying "if you abuse this system it will go away" because by
that time the damage is done. It's better to not let them abuse it at
all.
Someone made a very good suggestion to fix up the obvious security hols
in your script. The first two lines should be:
#!/usr/local/bin/perl -wT
use strict;
You seem to be using the CGI::Carp module, or trying to. This makes me
puzzled as to why you aren't using the CGI module itself, rather than
attempting to read in the data by hand (and getting it wrong).
I also suggest installing Perl on your own machine, rather than trying
to debug it via your web-browser, since when it doesn't compile, it can
be a real pain in the ass (as you have found out).
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The wheel that squeaks the loudest is the one that gets the grease.
-- Josh Billings, "The Kicker"
------------------------------
Date: Sun, 5 Nov 2000 11:21:45 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Building a Module on Server without Install.pm
Message-Id: <slrn909a0p.ac5.mgjv@martien.heliotrope.home>
[For the next time, post your reply AFTER the suitably trimmed text you
reply to. It is easier to read, and in accordance with the accepted
posting rules on this group, and Usenet in general.]
On Sat, 04 Nov 2000 20:57:53 GMT,
MNJP <not.my.real.email@bellglobal.com> wrote:
>
> Just include the following sub into your program, call it in the beginning,
> and you'll have all the variables passed from the browser in the hash %FORM.
> It works for me every single time.
Oh, puhleeze. Not another cargo-cult solution.
Search this newsgroups for reasons not to do this. Unless you know what
you're doing, and you can do it _correctly_ don't. Unless you only have
some trivial stuff to do, don't do this.
Besides that, your 'solution' doesn't even start scratching at the
surface of all the things CGI.pm does.
The OP asked for CGI.pm. You offer the OP about 0.03% of the
functionality of that module, incorrectly implemented, and you expect
that to be ok?
The fact that it works for you 'every single time' just shows me that
that code hasn't really been subjected to rigorous testing.
To the OP:
create a directory under your home directory, and copy the module files
there. Since none of it needs to be compiled, there shouldn't be a
problem. Then put a 'usr lib' line in your program:
# tar xzvf CGI.pm-2.74.tar.gz
# cd CGI.pm-2.74
# mkdir -p $HOME/perl/lib
# cp -r CGI.pm CGI $HOME/perl/lib
and in your program
#!/usr/local/bin/perl
use warnings;
use strict;
use lib '/home/me/perl';
And tell your ISP to stop being silly. Prohibiting access to
ExtUtils::Install.pm isn't going to stop anyone. You can even install
your own copy of those modules in that directory that you just created,
and set your PERL5LIB environment variable.
Martien
--
Martien Verbruggen |
Interactive Media Division | System Administration is a dirty
Commercial Dynamics Pty. Ltd. | job, but someone said I have to do
NSW, Australia | it.
------------------------------
Date: Sun, 05 Nov 2000 00:44:26 GMT
From: "MNJP" <not.my.real.email@bellglobal.com>
Subject: Re: Building a Module on Server without Install.pm
Message-Id: <K32N5.15621$1C6.790566@news20.bellglobal.com>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn909a0p.ac5.mgjv@martien.heliotrope.home...
> [For the next time, post your reply AFTER the suitably trimmed text you
> reply to. It is easier to read, and in accordance with the accepted
> posting rules on this group, and Usenet in general.]
>
> On Sat, 04 Nov 2000 20:57:53 GMT,
> MNJP <not.my.real.email@bellglobal.com> wrote:
> >
> > Just include the following sub into your program, call it in the
beginning,
> > and you'll have all the variables passed from the browser in the hash
%FORM.
> > It works for me every single time.
>
> Oh, puhleeze. Not another cargo-cult solution.
>
> Search this newsgroups for reasons not to do this. Unless you know what
> you're doing, and you can do it _correctly_ don't. Unless you only have
> some trivial stuff to do, don't do this.
I guess I do fall under the category "know what you're doing and doing it
correctly" Sine I have developed online banking commerce systems, web
portals, a webmail system from the ground-up, and much more.
I will repeat it: In *MY* experience I have never had the need for that
library. I grab what's passed to me using this sub I provided and the rest
is up to my program (and let me assure you I have done some pretty clever
things with "the rest")
I guess these are the differences between a senior developer and a systems
administrator.
>
> Besides that, your 'solution' doesn't even start scratching at the
> surface of all the things CGI.pm does.
>
> The OP asked for CGI.pm. You offer the OP about 0.03% of the
> functionality of that module, incorrectly implemented, and you expect
> that to be ok?
>
> The fact that it works for you 'every single time' just shows me that
> that code hasn't really been subjected to rigorous testing.
>
> To the OP:
>
> create a directory under your home directory, and copy the module files
> there. Since none of it needs to be compiled, there shouldn't be a
> problem. Then put a 'usr lib' line in your program:
>
> # tar xzvf CGI.pm-2.74.tar.gz
> # cd CGI.pm-2.74
> # mkdir -p $HOME/perl/lib
> # cp -r CGI.pm CGI $HOME/perl/lib
>
> and in your program
>
> #!/usr/local/bin/perl
> use warnings;
> use strict;
> use lib '/home/me/perl';
>
> And tell your ISP to stop being silly. Prohibiting access to
> ExtUtils::Install.pm isn't going to stop anyone. You can even install
> your own copy of those modules in that directory that you just created,
> and set your PERL5LIB environment variable.
>
> Martien
> --
> Martien Verbruggen |
> Interactive Media Division | System Administration is a dirty
> Commercial Dynamics Pty. Ltd. | job, but someone said I have to do
> NSW, Australia | it.
------------------------------
Date: Sun, 5 Nov 2000 12:11:45 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Building a Module on Server without Install.pm
Message-Id: <slrn909cuh.ac5.mgjv@martien.heliotrope.home>
On Sun, 05 Nov 2000 00:44:26 GMT,
MNJP <not.my.real.email@bellglobal.com> wrote:
[rewrapped and reformatted article to make it a bit more readable]
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn909a0p.ac5.mgjv@martien.heliotrope.home...
> > On Sat, 04 Nov 2000 20:57:53 GMT,
> > MNJP <not.my.real.email@bellglobal.com> wrote:
> > >
> > > Just include the following sub into your program, call it in the
> > > beginning, and you'll have all the variables passed from the
> > > browser in the hash %FORM. It works for me every single time.
> >
> > Oh, puhleeze. Not another cargo-cult solution.
> >
> > Search this newsgroups for reasons not to do this. Unless you know what
> > you're doing, and you can do it _correctly_ don't. Unless you only have
> > some trivial stuff to do, don't do this.
>
> I guess I do fall under the category "know what you're doing and doing it
> correctly" Sine I have developed online banking commerce systems, web
> portals, a webmail system from the ground-up, and much more.
The problem stays the same. You're giving people a piece of cargo cult
that they can use, which will bite them unless they know what they're
doing. They most likely don't know what they are doing.
Besides that, if you aim to impress with that list, you fail. Many
things have been implemented in this world, and are highly successful,
commercially, without impressing me one single bit. The three things
above may sound nice on a resume, and they contain all the hip and
web-savvy keywords, but tat doesn't mean a thing. The code matters, and
that's what could impress me.
> I will repeat it: In *MY* experience I have never had the need for that
> library. I grab what's passed to me using this sub I provided and the rest
> is up to my program (and let me assure you I have done some pretty clever
> things with "the rest")
Your experience is much more limited than the experience of the total
userbase of CGI.pm.
> I guess these are the differences between a senior developer and a systems
> administrator.
You don't know what I do, who I am, or what my qualifications are. Don't
assume you do because you read a signature that is randomly generated
from a larger set.
Do you always respond to slight criticisms -- and a fairly standard one
on this group at that -- by slinging out your private parts for size
comparison?
> > Besides that, your 'solution' doesn't even start scratching at the
> > surface of all the things CGI.pm does.
> >
> > The OP asked for CGI.pm. You offer the OP about 0.03% of the
> > functionality of that module, incorrectly implemented, and you expect
> > that to be ok?
And you forgot to say anything about this. I'll repeat it. The OP asked
for CGI.pm. Maybe they wanted the cookie stuff, or the persistency
stuff. Maybe they wanted to use it to generate HTML (which is what I
often use it for). Maybe they didn't really feel like doing any of the
stuff that CGI.pm does themselves, just like I don't think it's
interesting to implement that stuff myself any more. Been there, done
that.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: Sat, 04 Nov 2000 17:17:50 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Building a Module on Server without Install.pm
Message-Id: <3A04B53E.4AFF444E@vpservices.com>
MNJP wrote:
>
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn909a0p.ac5.mgjv@martien.heliotrope.home...
> >
> > On Sat, 04 Nov 2000 20:57:53 GMT,
> > MNJP <not.my.real.email@bellglobal.com> wrote:
> > >
> I guess I do fall under the category "know what you're doing and doing it
> correctly" Sine I have developed online banking commerce systems, web
> portals, a webmail system from the ground-up, and much more.
No, you fall in the category of "have been lucky so far". There is a
difference between code which works in certain limited situations and
code which has been peer reviewed by hundreds of professionals. I too
have many large and complex sites under my belt which did the job I was
paid to do but which I would not therefore claim are good code that
others should follow.
> (and let me assure you I have done some pretty clever
> things with "the rest")
I have no doubt you are quite clever however if you were really as
Perl-savy as you claim, I would have expected you to be familiar with
the archives of this newsgroup, to be familiar with the many benefits of
CGI.pm (perhaps the mostly widely used of any Perl module) and with
Martien's record and reputation. Since you appear to be familiar with
none of those things one wonders how good you could really be. If you
had said "I have thoroughly reviewed the code in CGI.pm and am familiar
with the arguments for and against it and I prefer my code for reasons
X,Y,Z" we might have had something to discuss (and there are certainly
*a few* in this newsgroup who could make such claims). But your out of
hand dismissal of a module that is highly regarded and that you yourself
state you have no knowledge of, makes all your other claims suspect.
> I guess these are the differences between a senior developer and a systems
> administrator.
The title on the door might get you a carpet on the floor, but it means
absolutely nothing in terms of proof of your ability to code good Perl.
Those who follow this newsgroup have seen hundreds (actually probably
more like thousands) of competent and original code snippets from
Martien and none form you. Whom should we beleive?
--
Jeff
------------------------------
Date: Sun, 05 Nov 2000 01:54:34 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Building a Module on Server without Install.pm
Message-Id: <1ejlrzj.qmq32tirzuwwN%tony@svanstrom.com>
MNJP <not.my.real.email@bellglobal.com> wrote:
> I guess I do fall under the category "know what you're doing and doing it
> correctly" Sine I have developed online banking commerce systems, web
> portals, a webmail system from the ground-up, and much more.
So what, anyone can write code that looks like it's doing what it's
supposed to without knowing what they are doing nor doing it correctly.
/Tony
--
/\___/\ Who would you like to read your messages today? /\___/\
\_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
--oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
on the verge of frenzy - i think my mask of sanity is about to slip
---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
\O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: Sun, 05 Nov 2000 00:04:37 +0000 (GMT)
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Re: File locking
Message-Id: <4a18698264g.soper@soundhouse.co.uk>
In article <h26evskc3u5m9uidpq2koidbrh7doc527b@4ax.com>, Bart Lateur
<bart.lateur@skynet.be> wrote:
> Geoff Soper wrote:
> >But...
> >
> >in one part of the code a file is modified and written to a new file
> >('something.new'). When this process is completed the old file is
> >renamed to 'something.old' and the new file is renamed to 'something'.
> >Do I need to apply for an exclusive lock before renaming the old file?
> I think it's one of those cases where locking the files you're working
> with, isn't enough. You can't lock a file that gets renamed. You may be
> able to lock the *contents* of the file, but on Unix these two things
> can be separated. For example, if you delete a file while it's open, the
> contents of the file will keep existing until the file is fully closed.
> An independent sign flag seems like a better idea to me. Create an extra
> file, and lock that. As long as it is locked, this is a signal of the
> script to it's twin brothers, that none of these files may be changed,
> and shouldn't be treated as permanent. For example, your script should
> reopen and reread the file "something", which may be a different file
> from before, when it got the lock on this general flag.
OK, in that case will the following three operations be sufficient?
Opening to read:
Open lock file ('something.lock') with non-exclusive lock:
open(LOCKFILE "<something.lock") or die "can't open filename: $!";
flock(LOCKFILE, LOCK_SH) or die "can't lock filename: $!";
Open and read file ('something')
Close file ('something')
Close lock file ('something.lock')
close(LOCKFILE);
Opening to write:
Open lock file ('something.lock') with exclusive lock:
sysopen(LOCKFILE, "something.lock" , O_WRONLY | O_CREAT) or die
"can't open filename: $!";
flock(LOCKFILE, LOCK_EX) or die "can't lock filename: $!";
Write to file ('something')
Close file ('something')
Close lock file ('something.lock')
close(LOCKFILE);
Locking to rename:
Open lock file ('something.lock') with exclusive lock:
sysopen(LOCKFILE, "something.lock" , O_WRONLY | O_CREAT) or die
"can't open filename: $!";
flock(LOCKFILE, LOCK_EX) or die "can't lock filename: $!";
Rename existing file ('something') to 'something.old.1'
Rename 'something.new' to 'something'
Close lock file ('something.lock')
close(LOCKFILE);
This is going on information gleaned from the FAQ and perlopentut. I don't
quite understand the use of 'sysopen' when an exclusive lock is required.
I understand that it needs to be atomic to avoid the race condition
between opening and locking but how does using 'sysopen' achieve this?
Many thanks
--
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/
------------------------------
Date: Sat, 04 Nov 2000 23:31:22 GMT
From: "MNJP" <not.my.real.email@bellglobal.com>
Subject: Re: Freelance Programmer Needed
Message-Id: <e%0N5.15476$1C6.778392@news20.bellglobal.com>
Boring.
"Lee Denny" <lee@areality.co.uk> wrote in message
news:973269319.28874.0.nnrp-10.c2dee5ab@news.demon.co.uk...
> Sorry if this is the wrong group, but we need an urgent quote on the
> attached specification.
> Thanks in advance
>
>
>
------------------------------
Date: Sat, 4 Nov 2000 23:53:36 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: How to check passwd is correct?
Message-Id: <Pine.GHP.4.21.0011042345270.26475-100000@hpplus03.cern.ch>
On Sun, 5 Nov 2000, Beggar wrote:
> How can I write a program in shell script or perl to
> test user's input passwd is correct compare with /etc/shadow?
This isn't a Perl question.
Don't do that, for the reasons shown in the Apache FAQ item.
Every attempt to use logon credentials for other purposes just
adds extra insecurity to the logon system.
> Is that need to use "crypt()" ? any other quick method or
> function that I can pass the input and compare the string to
> the shadow file's passwd field?
If you absolutely must check a user's credentials then ask the system
to do it for you. Don't try to hand code it. The whole reason the
shadow file is made readable only by root is for security reasons.
If you want any damned program to be able to read it, you might as
well not use shadow passwords.
> Please reply to "cpegbeggar@mail.com"
When you ask questions here, you expect to find answers here.
f'ups set.
------------------------------
Date: Sat, 04 Nov 2000 23:56:36 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: how to sort corresponding arrays?
Message-Id: <3a04a234.5467$135@news.op.net>
Keywords: browse, forbid, gasify, practicable
[mailed and posted]
In article <8u23qm$2ee$1@nnrp1.deja.com>, <drtsq@my-deja.com> wrote:
>I have two arrays that correspond to each other (@your_score, @answer).
@sorted_indices = sort { $your_score[$a] <=> $your_score[$b] }
(1 .. $#your_score);
@sorted_scores = @scores[@sorted_indices];
@sorted_answers = @answer[@sorted_indices]; # sorted in order by score
>These don't have to be seperate arrays, it could be a hash of arrays,
>but I still don't see how to do this. Any pointers?
See
http://perl.plover.com/yak/hw2/slide003.html
for more information.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Sat, 4 Nov 2000 18:42:41 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to sort corresponding arrays?
Message-Id: <slrn9097nh.5tb.tadmc@magna.metronet.com>
On Sat, 04 Nov 2000 22:49:59 GMT, drtsq@my-deja.com <drtsq@my-deja.com> wrote:
>I have two arrays that correspond to each other (@your_score, @answer).
>By correspond, I mean that the value in $your_score[1] is the score for
>test 1, and $text[1] is the text description for test 1.
Sounds like a poor choice of data structure.
>For reasons out of my control, the array starts at 1, not 0.
I'm not sure what that means.
Does that mean that $[ has been changed from the default? Or does
it mean that the zeroith element should be ignored?
>I want to print these sorted descending from highest score to lowest.
Err, you have neglected to mention _what_ you want to sort on.
Do you want to sort based on the answers or the scores?
I'll assume scores as sort keys.
>What I've go so far doesn't sort:
>
> for $ca (1 .. $#text) {
> print "score = $your_score[$ca], $text[$ca] <BR>" ;
> }
>
>
>These don't have to be seperate arrays, it could be a hash of arrays,
I think an array of hashes would be the most natural datastructure.
$tests[1]{score} = 99;
$tests[1]{answer} = 42;
>but I still don't see how to do this. Any pointers?
Sort a list of the _indexes_ rather than the values from the array(s).
------------------------
#!/usr/bin/perl -w
use strict;
my @score = qw/0 1 11 10 2/;
my @answer = qw/zero one eleven ten two/;
foreach my $ca ( sort { $score[$a] <=> $score[$b] } 1..$#score ) {
print "score = $score[$ca], $answer[$ca]\n" ;
}
------------------------
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 04 Nov 2000 23:28:49 GMT
From: "Bill Hess" <billhess2000@home.com>
Subject: kill on Win32
Message-Id: <RY0N5.79888$hD4.18487743@news1.rdc1.mi.home.com>
I am using Standard Perl I built myself 5.005_03 and am trying to kill
processes given a process ID
Below are two simple scripts to demo what I am trying to do - the first gets
the process ID and loops forever and the second justs performs the kill
function in Perl. I run the first and it tells me what the PID is and then
run the other in another shell and supply the PID as the first arg. I get
the following message after running Script 2:
kill process failed!
How can I kill the process from Perl???
# Script 1
$pid = $$;
while (1) {
print "PID = '$pid'\n";
sleep 20;
}
#Script 2
kill 'INT', $ARGV[0];
--
Bill Hess
------------------------------
Date: Sat, 04 Nov 2000 23:27:24 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Perl syntax and beyond (was: Re: Perl style and module searches)
Message-Id: <slrn9096qq.kpd.tjla@thislove.dyndns.org>
I was shocked! How could Bart Lateur <bart.lateur@skynet.be>
say such a terrible thing:
>Gwyn Judd wrote:
>
>>Well I think extending the syntax to have a linked list data type would
>>be nice.
>
>Ok. How would you imagine that syntax to be?
Completely off the top of my head, I have no idea. The only trouble with
Perl is that it seems to have overloaded all the characters on the
keyboard to such an extent that it's getting difficult to extend it any
further. I think Perl 6 should be written in kanji that way we won't
have to worry about running out for at least another hundred years. :)
hmm, how about:
^list = qw(a b c d e f g); # '^' is the linked list character
foreach (^list)
{
if ($_ eq 'b')
{
$_ *> 'd'; # insert a 'd' after the current item.
}
if ($_ eq 'd')
{
$_ *< 'x'; # insert before the current item
}
if ($_ eq 'f')
{
delete $_; # most regular operators should work as normal on
# list items
}
}
@array = ^list; # should be able to copy to and from as normal
I have no idea if this is feasible.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
New Jersey is not the armpit of the nation; it's the asshole of the universe.
-- Jonathan Michael Smith
------------------------------
Date: Sun, 5 Nov 2000 09:58:13 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: String manipulation??
Message-Id: <slrn909545.ac5.mgjv@martien.heliotrope.home>
On Sat, 4 Nov 2000 09:33:27 +0000,
James Taylor <james@NOSPAM.demon.co.uk> wrote:
>
> Wow, I wonder how I managed to miss that on first reading.
> Perhaps my mind filtered it out subconsciously judging it
> to be an unimportant nuance of an outdated calling mechanism.
> I see now, that the & calling mechanism has its uses.
The & calling mechanism is even more useful together with goto, but I am
not sure whether that is part of this discussion, or it isn't. A goto
&sub performs some nice magic, that can be useful in many cases for
autoloaders.
Martien
--
Martien Verbruggen |
Interactive Media Division | System Administration is a dirty
Commercial Dynamics Pty. Ltd. | job, but someone said I have to do
NSW, Australia | it.
------------------------------
Date: Sat, 04 Nov 2000 23:29:39 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Unix commands via perl?
Message-Id: <slrn9096uu.kpd.tjla@thislove.dyndns.org>
I was shocked! How could Jeff Pinyan <jeffp@crusoe.net>
say such a terrible thing:
>On Nov 4, Gwyn Judd said:
>
>>>> How many licks does it take to get to the center of a tootsie pop?
>>>
>>>Doesn't the centre keep moving as you lick so you never actually get there?
>>
>>On behalf of all the mystified non-merkins: What's a tootsie-pop?
>
>Gwyn, just how many of the readers of clpm do you think are merkins?! Are
>the non-merkins all quims? ;)
At least 50% (for some definition of '%'). What's a quim?
>A tootsie-pop is a round lollipop with a tootsie roll (chewy candy) in the
>center.
Aha, sounds yummy, considering I'm hungry.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
America is the only country that went from barbarism to decadence without
civilization in between.
-Oscar Wilde (contributed by Chris Johnston)
------------------------------
Date: Sun, 5 Nov 2000 01:49:54 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Unix commands via perl?
Message-Id: <Pine.GHP.4.21.0011050147040.2247-100000@hpplus03.cern.ch>
On Sat, 4 Nov 2000, Gwyn Judd wrote:
> >Gwyn, just how many of the readers of clpm do you think are merkins?! Are
> >the non-merkins all quims? ;)
>
> At least 50% (for some definition of '%'). What's a quim?
That's off-topic for this group - try alt.usage.english where IIRC
this topic has been done to death, including the literal (as opposed
to the alliterative) meaning of "merkin".
--
"and as all students have their whim,
he up and grabbed her by the ...."
------------------------------
Date: 4 Nov 2000 23:58:11 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Weak References Was: Keeping a List of Objects
Message-Id: <8u27qj$q7o$1@lublin.zrz.tu-berlin.de>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
>[posted and mailed]
>
>Ilya Zakharevich <ilya@math.ohio-state.edu> wrote in comp.lang.perl.misc:
>>[A complimentary Cc of this posting was sent to Anno Siegel
>><anno4000@lublin.zrz.tu-berlin.de>],
>>who wrote in article <8u1ius$pjv$1@lublin.zrz.tu-berlin.de>:
>>> Weak references seemed to work as expected in first tests, but
>>> putting the mechanism under stress reveals that "experimental" is
>>> there for a reason. Stress in this case means that I ended up with
>>> objects of two kinds -- those to which weak references exist, and
>>> those which contain weak references -- some stored in lexical variables
>>> and others in exported package variables[1]. In this situation I
>>> got to see
>>>
>>> panic: magic_killbackrefs, <DATA> line 38 during global destruction (#1)
>>
>>Hmm... As I designed it, weak references should work even when
>>surviving until global destruction, though this is not supposed to be
>>the primary way to use them. Can you supply a short test script?
>
>That may take a bit. I haven't been able to reproduce the error
>outside the rather involved original. While trying to par it down
>I'm seeing unexpected behavior of our() variables with respect to
>destructors that is unrelated to WeakRef, but it's not yet clear if
>it will lead to a slap on the forehead or a bug report.
Well, it looks like a bug to me. I'm presenting the code below
for comment. Again, this is not (yet) about WeakRef, but it turns
up before I can reproduce the WeakRef error.
The code shows the skeleton of two classes. The objects of one (Gen)
are generators of objects of the other (Obj). Each Obj object
remembers its individual generator. This reference isn't weak (and
shouldn't be, a generator must stay alive as long as any of its
objects are exist). This setup doesn't look very unusual.
When the User of the the classes decides to store one of the
generated objects in a package variable, and mentions the variable
last thing in the code (in void context), and warnings happen
to be switched on, then strange things happen during destruction.
In particular, the generated object turns up with an undefined
value where its generator should be (and has been).
Oh, and: This is perl, v5.6.0 built for i586-linux.
Anno
----------------------------------------------------------------
#!/usr/bin/perl
use strict; use warnings; $| = 1;
package Gen;
sub new {
bless {}, shift;
}
sub obj { # method for generating Obj objects
my $self = shift;
_new Obj $self; # remember who created you
}
package Obj;
sub _new {
my $class = shift;
my $gen = shift; # the generator
die "Gah!\n" unless defined $gen; # never let an undef gen pass
bless { gen => $gen}, $class;
}
sub DESTROY {
my $self = shift;
print "destroying $self\n";
# $self->{ gen} should never be undef at this point
print "gen undef in destruction\n" unless defined $self->{ gen};
}
package main;
my $gen = new Gen;
our $obj = $gen->obj; # changing our to my makes the error go away
print "generator defined\n" if defined $obj->{ gen}; # peeking in
# no warnings; # activating this makes the error go away
$obj; # commenting this out makes the error go away
------------------------------
Date: Sat, 4 Nov 2000 16:55:22 -0500
From: "José Isaías Cabrera" <jicman@cinops.xerox.com>
Subject: Why would subs not get the right args?
Message-Id: <8u20i2$kbs$1@news.wrc.xerox.com>
Hi all!
I have a very long job, and some of my subroutines are not working right.
for instance...
perl code
.
.
$month = 'jan';
$hello = checkifRightMonth($month);
sub checkifRightMonth
{
my $ckmon = @_;
print $ckmon;
}
this prints '1', when it should print 'jan'. What the heck is going on?
I've tried this on an NT and W2000. The script is pretty long and I am
reading 1.5 Meg of text into an array, but that should not make the
subroutines go crazy. Or should it?
any help would be appreciated. thanks.
I am using:
16:47:44.07>perl -v
This is perl, v5.6.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2000, Larry Wall
Binary build 617 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 20:32:54 Aug 31 2000
Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5.0 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
------------------------------
Date: Sun, 5 Nov 2000 12:24:26 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Why would subs not get the right args?
Message-Id: <slrn909dma.ac5.mgjv@martien.heliotrope.home>
On Sat, 4 Nov 2000 16:55:22 -0500,
José Isaías Cabrera <jicman@cinops.xerox.com> wrote:
>
> I have a very long job, and some of my subroutines are not working right.
You mean that they are not working as you _want_ them to work. The one
you post is working just fine.
> $month = 'jan';
> $hello = checkifRightMonth($month);
>
> sub checkifRightMonth
> {
> my $ckmon = @_;
> print $ckmon;
> }
>
> this prints '1', when it should print 'jan'. What the heck is going on?
No, it should print 1. 1 is the number of elements in @_, and an array
in a scalar context returns the number of elements it contains. This is
described in the perldata documentation.
Do any of these:
my ($chkmon) = @_;
my $chkmon = $_[0];
my $chkmon = shift @_;
my $chkmon = shift;
See the perlfunc docuemntation for a description of shift.
> I've tried this on an NT and W2000. The script is pretty long and I am
> reading 1.5 Meg of text into an array, but that should not make the
> subroutines go crazy. Or should it?
No, it shouldn't, but are you sure that you _need_ to read 1.5 MB of
data into an array? It may very weel be that you do indeed need to read
it in memory, but I've found in the past that most people who thought
they did, could rewrite their code to process the file line by line.
It'd save a lot of memory. Perl will use a lot more than just the 1.5 MB
to store your data. This just doesn't scale very well. What if you need
to process a file that is 10 times larger? 50 times?
Martien
--
Martien Verbruggen |
Interactive Media Division | life ain't fair, but the root
Commercial Dynamics Pty. Ltd. | password helps. -- BOFH
NSW, Australia |
------------------------------
Date: Sat, 04 Nov 2000 17:22:35 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Why would subs not get the right args?
Message-Id: <3A04B65B.84E332AE@vpservices.com>
"José Isaías Cabrera" wrote:
>
> $month = 'jan';
> $hello = checkifRightMonth($month);
>
> sub checkifRightMonth
> {
> my $ckmon = @_;
> print $ckmon;
> }
>
> this prints '1', when it should print 'jan'. What the heck is going on?
Nope, it should print '1'. The symbol @_ is a list of items passed into
the sub. The scalar value $ckmon is therefore equal to the length of
that list, i.e. 1. If you want $ckmon to contain 'jan' you need to do
one of these:
my $ckmon = shift;
my $ckmon = $_[0];
my($ckmon)= @_;
--
Jeff
------------------------------
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 V9 Issue 4812
**************************************