[12085] in Perl-Users-Digest
Perl-Users Digest, Issue: 5685 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun May 16 09:09:16 1999
Date: Sun, 16 May 99 06:01:25 -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 Sun, 16 May 1999 Volume: 8 Number: 5685
Today's topics:
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" (Sam Holden)
Re: Perl "constructors" armchair@my-dejanews.com
Re: Perl "constructors" (Sam Holden)
Re: problem w/perl cgi script & background image <bmhart@mediaone.net>
Re: Saving regularly a web page <wjgray@email.com>
Single Thread CGI <corn@narfum.org>
Re: TROLL ALERT (Re: Perl "constructors") armchair@my-dejanews.com
Re: visual debugger for UNIX? <tchrist@mox.perl.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 16 May 1999 10:52:36 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hm81k$hem$1@nnrp1.deja.com>
In article <ylu2td1lcf.fsf@windlord.stanford.edu>,
Russ Allbery <rra@stanford.edu> wrote:
> armchair <armchair@my-dejanews.com> writes:
>
> Think of @{ ... } as a single construct, not two constructs @ and {
... }.
> The @ tells Perl that it's evaluating something to get an array ref,
and
> then looking at the actual array.
Okay, then {} does not derefernce by itself. That helps, thanks.
> --
> #!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
> $^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD
gD,
> 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.),
01,pnn,y{
> rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/
#y,d,s,(\$.),$1,gee,print
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Sun, 16 May 1999 11:07:02 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hm8sm$hre$1@nnrp1.deja.com>
In article <yllnep1kdh.fsf@windlord.stanford.edu>,
Russ Allbery <rra@stanford.edu> wrote:
> armchair <armchair@my-dejanews.com> writes:
>
> > I ask you to write a subroutine for me. It will receive a hash, one
of
> > who's keys is "input filename", and read the first line of the file
and
> > fill in the key "first line" with the first line of the file. You
are
> > wary that I might pass the hash correctly, but may have not filled
in
> > any key value of "input filename". What does your code look like
> > assuming that I have asked you to pass back 0 on success, 1 on file
open
> > error and 2 for bad parameter list? In other words, how do you get
> > around using exists()?
>
> Er, why on earth would you write it that way in Perl?
>
> sub first_line {
> my $filename = shift;
> open (FILE, $filename) or return undef;
> return <FILE>;
> }
> print first_line ('filename');
You didn't follow my spec, which had a specific purpose, which was not:
"how should I solve this particular problem?", but how would you check
for a missing hash key without using exists(). The filename is inside of
a hash that I am passing down as a reference (the hash reference is the
first parameter passed down.) And I want to know from the return code
exactly what failed - bad value of a parameter, missing parameter, file
not readable, file not found. You are only telling me something went
wrong. And the second parameter passed is a reference to an array where
I want the first line placed, not returned via return().
>
> That will return the first line of the given file, undef on failure to
> open the file, and the empty string if the file is empty. You'll find
> that all of the possible cases are well-defined. If you want to know
why
> the file couldn't be opened, the reason will be in $!.
I don't want to grep any reason in $!, because the wording may change or
be system dependent, or , if you don't like that, because I want it done
via a return code. Let me change the spec to say that I want an error
returned if stat() reveals that the file is less than 800 bytes. And, as
we have standardized here at our hypothetical programming shop that all
functions which do not receive parameters that are expected, must return
the value 10.
>
> One of the ways that Perl gets around having to have return codes in
> nearly every case is by having the value "undef" for indicating
> exceptional conditions like this. The concept of a return code is
very
> C/C++ and usually isn't needed in Perl.
How is returning undef superior to returning an integer value?
>
> --
> #!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
> $^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD
gD,
> 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.),
01,pnn,y{
> rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/
#y,d,s,(\$.),$1,gee,print
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Sun, 16 May 1999 11:16:39 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hm9en$i6l$1@nnrp1.deja.com>
In article <FYt%2.140$fx5.352@news.rdc1.sfba.home.com>,
"Stephen Warren" <swarren@www.wwwdotorg.org> wrote:
> <armchair@my-dejanews.com> wrote in message
> news:7hlkr4$4vt$1@nnrp1.deja.com...
> > In article <f9ljh7.gp4.ln@magna.metronet.com>,
> > tadmc@metronet.com (Tad McClellan) wrote:
> > > armchair@my-dejanews.com wrote:
> > > : In article <7uc%2.10345$L4.363390@news2.rdc1.on.home.com>,
> > > : andrew-johnson@home.com wrote:
> > >
> > > : > What makes you think that is what perl is doing?
> > >
> > > : Because the book I have - "Perl From the Ground Up" in it's
built-in
> > > : function reference says that keys "returns all the keys for the
Hash
> > > : named". It does not mention "scalar context" as some right
honorable
> > > : fellow was nice enough to point out that the perlfunc does
inside of
> > > : parenthese after stating the above regarding returning all the
keys.
> > >
> > > Problems with a book are problems with the book, not with Perl.
> > >
> > > If you have problems with a book, contact someone connected
> > > with producing the book.
> > >
> > > The only reference that matters are the docs that come with
perl.
> > >
> > > If you find a problem there, then mention it here.
> > >
> > > If you find a problem elsewhere then mention it elsewhere.
> >
> > I think you need a hobby Tad.
>
> He had one - helping out people in c.l.p.m who had questions about
Perl
> and were willing to listen to the free advice that was given out:-)
>
> You cannot possibly believe that just because a book exists and its
topic
> is computing then everything it says is complete and correct? Even
from
> typos or editing mistakes? You obviously never typed in 1000-line
listings
> of BASIC programs from computer magazines!
You obviously missed the point. I was responding to someone who was
crabbing at me for not knowing that keys() returns the number of entries
in a hash, when used in "scalar context". I was answering him by saying
that I had looked for an exlanation of keys() in "Perl From the Ground
Up" and it had the "returns array of the keys..." but didn't add the
parenthetically contained phrase " returns number of entries when used
in scalar context" that is in the Perl "manual". So it was not a
criticism of the book in any way. Just an explanation as to how I saw a
definition of keys, but did not know about the old "scalar context"
form. Then Tad comes in with "don't tell us about problems with any book
here.... blah blah". Then when I give him a flip answer, here comes you
with "how can you put your stock and faith in every line of a book...
blah blah". Again, I was responding to an incredulous query of how I
could not see that keys() returns a scalar in "scalar context".
>
> --
> Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
> mailto:swarren@techhouse.com http://www.techhouse.com/
> mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
> MIME, S/MIME and HTML mail are acceptable
>
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Sun, 16 May 1999 11:48:38 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hmbam$j76$1@nnrp1.deja.com>
In article <slrn7jsu0h.72t.sholden@pgrad.cs.usyd.edu.au>,
sholden@cs.usyd.edu.au wrote:
> On Sun, 16 May 1999 07:21:51 GMT, armchair@my-dejanews.com wrote:
> >In article <slrn7js8nd.d4q.sholden@pgrad.cs.usyd.edu.au>,
>
> I answered the question. I said look it up in the documentation.
>
> Just use 'return;' not 'return 0;'.
>
> So you would have...
>
> return bless $ref if $success;
> return;
>
> Though you might like to use if...else or unless.
I personally would return an int, not a value of undef, which is pretty
scary as it makes my variables disappear.
my $scalar = 0; my $scalar = my_sub(); print $scalar;
(W) An undefined value was used as if it were already defined.
It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign an initial value to your variables
And by your definition below, return 0; returns false in the land of
Perl, just as much as undef does.
>
> Perl doesn't use 0 to represent false. False in perl is anything which
> evaluates to "" or 0 or "0" and possibly some things I can't remember.
> Of course it depends on context as well. 0 isn't false in a list
context.
> It's in the documentation anyway. Perl uses anything that isn't false
> as true.
>
> To return false in perl you simply use return; So here's a sub that
> returns false.
>
> sub false { return;}
Perl does use 0 for false, it just uses string nil and string 0 as well
(very confusing that a variable can appear to contain the string "123"
and the number 123 at the same time). And it also appears to use undef
as false - else how does my_func() || or die 'didn't work' work if
my_func() is returning undef on failure?
>
> Too much topmind exposure on my part I guess...
Second time I have seen "topmind" - what exactly does it mean?
>
> I still think that if you hate all the things you say you hate, that
> perl is not the language for you. Python isn't either. I'm not sure
> what is since I like the things you don't and thus haven't looked
> for what you want.
As I said elsewhere, Perl has a large enough usage and momentum that it
is something that can be valuable for a computer programmer to know,
particularly regarding it's usage in Web pages, and the booming demand
software professionals in that area. And I have never used the word hate
or anything close to it, nor have I expressed any emotions close to it.
I have only made a couple of complaints, one of which was just an aside
(regarding reference being the only data in an object) and the other was
a suggestion really (new being a required name), and the final one was
just thrown in after I received so many zealous responses to my new()
suggestion (no variable typing - and I also made one comment about {}
being used to dereference as well as surround hash keys), but you
fellows on this newsgroup are of a mindset that causes you to put your
own negative and extreme interpretation on my words. You appear to have
a very large chip on your shoulders. Since Perl is growing in
popularity, not declining, and is used in a rapidly growing section of
the computer programming field, your defensiveness is striking. I was
being somewhat facetious before, but I think that you guys really should
air out any complaints you have about the language that may be lurking
in your psyche.
>
> --
> Sam
>
> Of course, in Perl culture, almost nothing is prohibited. My feeling
is
> that the rest of the world already has plenty of perfectly good
> prohibitions, so why invent more? --Larry Wall
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Sun, 16 May 1999 12:07:43 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hmcef$jtk$1@nnrp1.deja.com>
In article <w_t%2.141$fx5.427@news.rdc1.sfba.home.com>,
"Stephen Warren" <swarren@www.wwwdotorg.org> wrote:
> <armchair@my-dejanews.com> wrote in message
> news:7hlktt$58j$1@nnrp1.deja.com...
> > In article <slrn7js8rb.d4q.sholden@pgrad.cs.usyd.edu.au>,
> > sholden@cs.usyd.edu.au wrote:
> > > On Sat, 15 May 1999 12:42:58 GMT, armchair@my-dejanews.com wrote:
> > > >
> > > >Because the book I have - "Perl From the Ground Up" in it's
built-in
> > > >function reference says that keys "returns all the keys for the
Hash
> > > >named". It does not mention "scalar context" as some right
honorable
> > > >fellow was nice enough to point out that the perlfunc does inside
of
> > > >parenthese after stating the above regarding returning all the
keys.
> > >
> > > So the book is wrong. Throw it out and buy 'Programming Python'.
> >
> > I've got it! I was all pumped to learn Python until I saw that it
had
> > the same thing I didn't like about Perl - a variable can hold either
a
> > string or a number at any time.
>
> IIRC... This'll blow your mind: In Perl (don't know about Python), a
> variable can hold a string and a numeric value at the *same* time...
>
> Of course, the string would just be a textual representation of the
number
> stored, but...
Yes, I have seen that code as in:
my $scalar = "100";
$scalar += 10;
print $scalar; # prints 110
very disturbing indeed.
Even more disturbing is the check provided in the perldata HTML page:
To find out whether a given string is a valid nonzero number, it's
usually enough to test it against both numeric 0 and also lexical ``0''
(!!!! ALTHOUGH THIS WILL CAUSE -W NOISES !!!!). That's because strings
that aren't numbers count as 0, just as they do in awk:
if ($str == 0 && $str ne "0") {
warn "That doesn't look like a number";
}
>
> --
> Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
> mailto:swarren@techhouse.com http://www.techhouse.com/
> mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
> MIME, S/MIME and HTML mail are acceptable
>
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: 16 May 1999 12:20:48 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Perl "constructors"
Message-Id: <slrn7jte10.fth.sholden@pgrad.cs.usyd.edu.au>
On Sun, 16 May 1999 11:48:38 GMT, armchair@my-dejanews.com wrote:
>In article <slrn7jsu0h.72t.sholden@pgrad.cs.usyd.edu.au>,
> sholden@cs.usyd.edu.au wrote:
>> On Sun, 16 May 1999 07:21:51 GMT, armchair@my-dejanews.com wrote:
>> >In article <slrn7js8nd.d4q.sholden@pgrad.cs.usyd.edu.au>,
>
>
>>
>> I answered the question. I said look it up in the documentation.
>>
>> Just use 'return;' not 'return 0;'.
>>
>> So you would have...
>>
>> return bless $ref if $success;
>> return;
>>
>> Though you might like to use if...else or unless.
>
>I personally would return an int, not a value of undef, which is pretty
>scary as it makes my variables disappear.
> my $scalar = 0; my $scalar = my_sub(); print $scalar;
> (W) An undefined value was used as if it were already defined.
> It was interpreted as a "" or a 0, but maybe it was a mistake.
> To suppress this warning assign an initial value to your variables
But your not meant to print the error indicator, your just meant to test
it with if or || or or or unless, etc (I couldn't resist those ors).
>
>And by your definition below, return 0; returns false in the land of
>Perl, just as much as undef does.
Unless used like so :
my @array = my_sub();
>>
>> Perl doesn't use 0 to represent false. False in perl is anything which
>> evaluates to "" or 0 or "0" and possibly some things I can't remember.
>> Of course it depends on context as well. 0 isn't false in a list
>context.
>> It's in the documentation anyway. Perl uses anything that isn't false
>> as true.
>>
>> To return false in perl you simply use return; So here's a sub that
>> returns false.
>>
>> sub false { return;}
>
>Perl does use 0 for false, it just uses string nil and string 0 as well
>(very confusing that a variable can appear to contain the string "123"
>and the number 123 at the same time). And it also appears to use undef
>as false - else how does my_func() || or die 'didn't work' work if
>my_func() is returning undef on failure?
Since undef evaluates to the string "".
>
>
>>
>> Too much topmind exposure on my part I guess...
>
>Second time I have seen "topmind" - what exactly does it mean?
An annoying person - search the news archives for some wonderful
posts by him...
>
>>
>> I still think that if you hate all the things you say you hate, that
>> perl is not the language for you. Python isn't either. I'm not sure
>> what is since I like the things you don't and thus haven't looked
>> for what you want.
>
>As I said elsewhere, Perl has a large enough usage and momentum that it
>is something that can be valuable for a computer programmer to know,
>particularly regarding it's usage in Web pages, and the booming demand
>software professionals in that area. And I have never used the word hate
>or anything close to it, nor have I expressed any emotions close to it.
>I have only made a couple of complaints, one of which was just an aside
>(regarding reference being the only data in an object) and the other was
>a suggestion really (new being a required name), and the final one was
>just thrown in after I received so many zealous responses to my new()
>suggestion (no variable typing - and I also made one comment about {}
>being used to dereference as well as surround hash keys), but you
>fellows on this newsgroup are of a mindset that causes you to put your
>own negative and extreme interpretation on my words. You appear to have
>a very large chip on your shoulders. Since Perl is growing in
>popularity, not declining, and is used in a rapidly growing section of
>the computer programming field, your defensiveness is striking. I was
>being somewhat facetious before, but I think that you guys really should
>air out any complaints you have about the language that may be lurking
>in your psyche.
I don't have any serious complaints. I don't like the OO model that perl
uses, but it is workable, and I don't use it that often anyway. I don't
like the way someone always comes up with a better solution to a problem
in perl than I do, but that'snot perl's fault.
I noticed you not liking some parts of perl. If I felt that way about
programming languages I wouldn't use perl. You obviously still would.
That's fine poeple aren't the same after all. I don't use a language
becuase it is popular or valuable. I learn them out of some need or
interest. I learnt perl since it was all I had available many years ago
for a job I was doing. I liked it and stuck with it. I learnt ASP a year
ago since it was all I had available for a job I was doing. I didn't
like it. I left the job.
I don't expect people to view things the same way as me, although I
often assume they do when I have no further info. I'm usually wrong,
but those are the breaks I guess...
--
Sam
Perl is the Cliff Notes of Unix.
--Larry Wall
------------------------------
Date: Sun, 16 May 1999 12:17:23 GMT
From: armchair@my-dejanews.com
Subject: Re: Perl "constructors"
Message-Id: <7hmd0i$k8o$1@nnrp1.deja.com>
In article <yl3e0x1fzg.fsf@windlord.stanford.edu>,
Russ Allbery <rra@stanford.edu> wrote:
> armchair <armchair@my-dejanews.com> writes:
>
> > And the poster was complaing about what is often referred to as
> > Hungarian notation variable naming, something that was popularized
by a
> > legendary programmer named Charles Simonyi, who wrote the first GUI
word
> > processor at Xerox PARC before moving on to Microsoft.
>
> I know where it came from. I've read his writings on the topic. I
used
> Hungarian notation for years myself and then decided it wasn't buying
me
> anything at all beyond making my variable names longer and harder to
read.
> I'm not dissing it without practical experience.
>
> In fact, Perl has a form of Hungarian notation built in, just enough
to
> not be as annoying and actually be somewhat useful. Adding Hungarian
> notation on *top* of that strikes me as redundant and ugly.
If there was a separate notation for reference scalar, number scalar,
and string scalar, it would be redundant, but their ain't, so it ain't.
>
> > I would guess that a very tiny amount of the people who look at that
> > variable naming convention could have written the first GUI word
> > processor,
>
> That doesn't mean he's good at coding style decisions, just that he's
good
> at writing applications.
That doesn't mean that he's bad at coding sytle decisions, and it
implies that he is probably better at them than the average programmer.
>
> > I am sure that many among us would join me in saying that that type
of
> > thinking has no place in the Perl community where Art, Common Sense,
> > Linguistics and Computer Science converge.
>
> Please argue for yourself. People who try to make their arguments
sound
> better by inventing other people who also support them sound like
they're
> trying to get support from imaginary friends.
Who did I invent? And who suggested that Perl is where ART, Common
Sense, Liquistics and Computer Science converge?
>
> --
> #!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
> $^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD
gD,
> 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.),
01,pnn,y{
> rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/
#y,d,s,(\$.),$1,gee,print
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: 16 May 1999 12:32:38 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Perl "constructors"
Message-Id: <slrn7jten6.fth.sholden@pgrad.cs.usyd.edu.au>
On Sun, 16 May 1999 12:07:43 GMT, armchair@my-dejanews.com wrote:
>
>Yes, I have seen that code as in:
>
>my $scalar = "100";
>$scalar += 10;
>print $scalar; # prints 110
>
>very disturbing indeed.
But that's just bad programming. It becomes extremely useful for things like :
my $scalar = <>;
$scalar+=10;
print $scalar;
Since you don't have to much around with converting a string to a number.
It's also very useful like this :
my $count = 10;
print "The count is $count\n";
--
Sam
Anyway, the other successor to C gobbled up two letters instead of one.
Which is why many Perl scripts have the extension, ``.pl'', finishing
off BCPL. --Larry Wall
------------------------------
Date: Sun, 16 May 1999 08:02:02 -0400
From: "Brad & Melissa Hart" <bmhart@mediaone.net>
Subject: Re: problem w/perl cgi script & background image
Message-Id: <vyy%2.3308$AL5.5607@ndnws01.ne.mediaone.net>
This might be stating the obvious, but is background.gif in the same
directory as the perl script? You do not give any relative pathname to it,
so it needs to be in the same directory.
Just a quick thought.
-Brad
rcastro wrote in message <373eebc1@news1.jps.net>...
>Hi,
>I'm having problems with one of my Perl CGI scripts.
>I want the script to generate a web page that uses
>a background image (a .gif file).
>
>To illustrate what happens, go to:
>
>http://www.jps.net/rcastro/test.html
>
>This shows how the page is SUPPOSED to look.
>
>Now go to:
>
>http://www2.jps.net/cgi-bin/cgiwrap/rcastro/test.cgi
>
>This is the same page, except the HTML is generated
>by my CGI script, and I can't get the background to show
>up. Any ideas???? The source code is the same, the gif
>is the same, the file permissions are the same - the only
>difference is that one page is static HTML and the other
>is generated by a Perl script. The one generated by
>the Perl script won't display the background image properly.
>
>If anybody knows what I am doing wrong, please email me
>at rcastro@jps.net
>
>Thanks,
>Randy
>
>Here is my Perl script:
>=========================
>#!/usr/local/bin/perl
>use CGI;
>$ans = new CGI;
>
>print $ans->header;
>
>print $ans->start_html(-BACKGROUND=>'background.gif');
>print ("<center>\n");
>print ("<h2>Can you see the pretty background?</h2>\n");
>print ("</center>");
>
>print $ans->end_html;
------------------------------
Date: Sun, 16 May 1999 11:57:26 GMT
From: wjgray <wjgray@email.com>
Subject: Re: Saving regularly a web page
Message-Id: <7hmbr7$ji6$1@nnrp1.deja.com>
> So perhaps my question is: how can I launch a perl program regularly
on
> my Windows system ?
Check out AT services and/or "Scheduled Tasks"....
>Perhaps it's not the appropriate newsgroup...
Probably not...
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Sun, 16 May 1999 14:20:49 +0200
From: Karel Bemelmans <corn@narfum.org>
Subject: Single Thread CGI
Message-Id: <373EB821.2F749232@narfum.org>
Hello all,
(this is the first time I read this newsgroup, so this question might
already been asked...)
I have a MessageBoard written in perl. It's a modification of Matt
Wright's WWWBoard. The script simple generates html pages and updates a
msglist.html file where an index is kept of all the messages posted.
Posting and reading works fine, but when 2 users try to post at the same
time, things get screwed up with the msglist.html file and the counter
of a new message.
I tried to fix those problems by making use of a lock file that is set
when the script starts and released when it's finished, but that didn't
help.
My question now is, is there some way of making a perl script running
single thread ? So you just can run it once, and other people trying to
use it meanwhile get a "Script busy" error. In Java servlets there is a
way of doing that, but I first would like to know different solutions
before converting all my work to Java.
Thanks in advance,
Karel
--
Karel Bemelmans, corn@narfum.org
Narfum Inc., http://www.narfum.org
"Information wants to be $4.95."
------------------------------
Date: Sun, 16 May 1999 12:02:05 GMT
From: armchair@my-dejanews.com
Subject: Re: TROLL ALERT (Re: Perl "constructors")
Message-Id: <7hmc3t$jrb$1@nnrp1.deja.com>
In article <ylr9oh1l1g.fsf@windlord.stanford.edu>,
Russ Allbery <rra@stanford.edu> wrote:
> armchair <armchair@my-dejanews.com> writes:
> > Russ Allbery <rra@stanford.edu> wrote:
>
> >> To me, a constructor is a function that I call to get a new object
of a
> >> given type. This isn't how C++ uses the term, but it's the
*intuitive*
> >> definition of the term for me. C++ therefore has all sorts of
> >> constructors that aren't named "new()"; anything that creates a new
> >> object and returns it is a constructor.
>
> >> If you really want to use C++'s definition for constructor, Perl
*does*
> >> only have one constructor. bless().
>
> > In C++ the constructor (member function that creates an object of
that
> > class) has the exact same name as the class of the object it is
> > constructing. Their are no exceptions. [...]
>
> > "new" is a reserved word that is used to dynamically allocate
memory.
>
> Yes, yes, I know, I'm glossing over the details. new is the normal
way of
> calling a constructor in C++; I know that the method isn't actually
named
> that, and that you can also just allocate an object off the stack and
the
> constructor gets called that way.
If you are saying that the normal way to construct an object is on the
heap via:
MyClass *pClass = new MyClass();
I don't think that I would agree with that. It certainly isn't the way I
normally do it. I would say it is much less common where I work. And the
new is not part of the class constructor, it is still just used to
allocate memory dynamically.
>
> The point still stands, however. Perl objects are fundamentally very
> different things than C++ objects; they don't inherently do any
> initialization when they're created, and anyone can create an object
> called anything they want. Perl gives you a lot more control over the
> entire process. You can do things the C++ way, but you can also do
them a
> lot of other interesting ways.
>
C++ objects do not inherently initialize themselves. It has to be coded
by the programmer. You will have unknown values even in an int, should
you have one in your class and not initialize it. C++ gives you complete
control over the process as well. C++, as I mentioned before, actually
gives you more ways to make a class than Perl does. I would have to say
the converse is true - C++ gives you more flexibility.
> > A member function may create an instance of some other class, and
return
> > it, but that would not be called a "constructor" just because it is
> > "instantiating" or creating an object of another class.
>
> It's logically a constructor, however, which is my point. It
constructs
> an object. The C++ distinction is one of language semantics, not
actual
> usage in a program.
I am afraid you lose me on this. A constructor is a member function or
functions that create an object of a certain class type. If object a is
created in a member function Print() of object b, it just means that
the Print() function is calling the b constructor, not that Print() is a
constructor. Print() instantiates, but it doesn't construct anything,
that is left for b's constructor function to do.
>
> --
> #!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
> $^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD
gD,
> 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.),
01,pnn,y{
> rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/
#y,d,s,(\$.),$1,gee,print
>
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: 16 May 1999 06:12:27 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: visual debugger for UNIX?
Message-Id: <373eb62b@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Phil Yurchuk <liquidcool@hotbot.com> writes:
:I was wondering if there existed a reliable visual debugger for perl
:that ran under X. I'm developing on a Solaris 2.6 machine, and was
:hoping to find something like xxgdb. Does xemacs interact with the
:standard perl debugger?
Yes.
Or you can use vi.
#!/usr/bin/perl
# pvdb, a vi-aware front-end for the perl debugger
# tchrist@perl.com
# v2.0-alpha, Fri Mar 26 08:40:54 MST 1999
use strict;
use POSIX qw(setsid); # XXX: called unnecessarily sometimes
use Config; # XXX: called unnecessarily sometimes
$ENV{PATH} .= ":/etc";
my $FIONREAD;
my $TIOCSTI;
# XXX: this gets (at least :-) called twice
($FIONREAD, $TIOCSTI) = get_config();
if (defined $ARGV[0] && $ARGV[0] eq '-v') {
shift;
slave_vi(@ARGV);
} else {
run_debugger(@ARGV);
}
exit;
my(
$file,
$fifo,
$iopid,
$xtpid,
$kidpid,
$tty,
@kidpids,
);
sub run_debugger {
$file = shift || die "usage: $0 file [args]\n";
-r $file or die "can't read $file: $!";
$fifo = "/tmp/pvd-fifo.$$";
unlink $fifo;
$SIG{INT} = 'IGNORE';
#system("mknod $fifo p") and die "mknod failed";
system("mkfifo $fifo") and die "mknod failed"; # XXX: wrong path?
unless (defined ($iopid = fork)) {
die "can't fork: $!";
}
unless ($iopid) {
POSIX::setsid();
exec "xterm", -ah, # keep cursor bright
-wf, # wait to remap; XXX: doesn't work?
-fg => 'Navy',
-bg => 'Plum',
-n => "pvdb i/o",
-T => "pvdb i/o",
-fn => "6x10",
-geom => "85x25+3+4",
-e => 'sh', '-c', qq{
tty > $fifo;
sleep 10000000;
};
die "can't exec xterm: $!";
}
push @kidpids, $iopid;
open(FIFO, "< $fifo");
$tty = <FIFO>;
close FIFO;
unless (defined ($xtpid = fork)) {
die "can't fork: $!";
}
unless ($xtpid) {
POSIX::setsid(); # wish I remembered why I did this
exec "xterm",
-ah,
-wf,
-fg => 'Red',
-bg => 'LightSkyBlue1',
-n => "pvdb edit",
-T => "pvdb edit",
-fn => "6x10",
-geom => "85x55+349+4",
-e => $0, "-v", $fifo;
die "can't exec xterm: $!";
}
push @kidpids, $xtpid;
$| = 1;
# i hate having to hide, but the compiler sees this on both runs
# otherwise
eval q{
END {
local $SIG{CHLD} = 'IGNORE';
unlink $fifo;
kill "TERM" => @kidpids; # kill them; kill them all!
}
};
die if $@;
$SIG{CHLD} = sub {
unless (wait() == -1) {
print "Whoops, that debugger just exited.\n" ;
exit;
}
};
unless (defined ($kidpid = open(KID, "-|"))) {
die "can't fork: $!";
}
open(FIFO, ">$fifo") || die "can't open $fifo: $!";
select((select(FIFO), $| = 1)[0]);
unless ($kidpid) {
$ENV{PERLDB_OPTS} = "LineInfo=$fifo";
$SIG{INT} = 'DEFAULT'; # still needed?
open(STDOUT, ">$tty") || die "can't open $tty: $!";
open(STDERR, ">$tty") || die "can't open $tty: $!";
open(STDIN, "<$tty") || die "can't open $tty: $!";
# XXX: darned -emacs kills readline!
exec $^X, '-dS', $file, '-emacs', @_;
die "Can't exec debugger: $!"; # XXX: went to other tty
}
push @kidpids, $kidpid;
while ($_ = getline(*KID)) {
chomp;
my($file, $line) = /^(?:\032\032)?(.*?):(\d+):(\d+)/;
unless ($file =~ /\beval\b/) {
print FIFO "$file $line\n";
}
}
}
# I've simply decided that stdio is not a friend of mine.
sub getline {
my $fh = $_[0];
my $buf = '';
my $long = pack("L", 0);
for (;;) {
my $smask = '';
vec($smask, fileno($fh), 1) = 1;
my $ok = select($smask, undef, undef, $buf ? 0.25 : undef);
if (!$ok) {
return $buf if $buf;
warn "select: $!";
next;
}
ioctl($fh, $FIONREAD, $long) or die "can't FIONREAD: $!";
my $count = unpack("L", $long);
die "count is empty" unless $count =~ /\d/;
my $chars = '';
sysread($fh, $chars, $count);
$buf .= $chars;
if ($buf =~ /DB<\d+> $/ or $buf =~ /\n/) { # XXX: no more DB< ?
return $buf;
}
}
}
sub slave_vi {
my($tty,
$pid,
$fifo,
);
unless (@_ == 1 and -p ($fifo = shift)) { die "usage: $0 fifo"; }
my $editor = $ENV{EDITOR} || 'vi';
$SIG{TTOU} = 'IGNORE';
chomp($tty = `tty`);
open(TTY, "+> $tty") || die "no /dev/tty: $!";
die "can't fork: $!" unless defined ($pid = fork);
unless ($pid) {
exec $editor;
die "can't exec $editor";
}
jam (":set ro\n"); # read only
jam (":set nu\n"); # line numbers
open (FIFO, $fifo) || die "can't open $fifo: $!";
my $oldfile = '';
kill "WINCH" => $pid; # must resize cause xterm is confused
eval q{
END { unlink $fifo }
};
while (<FIFO>) {
unless (s/^\032\032//) {
print "GOT REGULAR INPUT: $_"; # XXX: what's this?
next;
}
chomp;
my($file, $line) = split /:/;
if ($file ne $oldfile && $file !~ /\beval\b/) {
# XXX: sometimes "unknown command" errors; why?
jam(":n +$line $file\n");
$oldfile = $file;
} else {
jam("${line}G");
}
}
}
# XXX: knows that TTY is open
sub jam {
for (split(//, $_[0])) {
ioctl(TTY, $TIOCSTI, $_) || die "bad TIOCSTI: $!";
}
}
sub get_config {
use Config;
if ($Config{archname} =~ /^i\d86-linux$/) {
return (0x541b, 0x5412)
}
elsif ($Config{archname} =~ /^OpenBSD.i\d86-openbsd$/) {
return (0x4004667f,0x80017472);
}
elsif ($Config{archname} =~ /^sun4-sunos$/) { # real sunos, not solaris
return (0x4004667f,0x80017472); # coincidence? :-)
}
else {
warn "No predefined sys values found";
}
eval { require "sys/ioctl.ph" };
my $fion = eval { &FIONREAD };
my $tioc = eval { &TIOCSTI };
if (2 == grep {defined} $fion, $tioc) {
return ($fion, $tioc);
}
print STDERR "No FIONREAD and TIOCSTI found in sys/ioctl.ph -- compiling...";
my $cfile = "/tmp/fiotio";
open(CSRC, "> $cfile.c") || die "can't open $cfile.c: $!";
eval q{ END { unlink($cfile, "$cfile.c") } };
print CSRC <<'EOF';
#include <sys/ioctl.h>
main() {
printf("%#x\n%#x\n", FIONREAD, TIOCSTI);
exit(0);
}
EOF
close CSRC or die "can't close $cfile.c: $!";
system("cc -o $cfile $cfile.c")
and die "can't compile $cfile.c";
($fion, $tioc) = split ' ', `$cfile`;
die "can't run $cfile $fion $tioc: $?" if $?;
print STDERR " using FIONREAD=$fion TIOCSTI=$tioc\n";
return map { hex } ($fion, $tioc);
}
--
"We all agree on the necessity of compromise. We just can't agree on
when it's necessary to compromise."
--Larry Wall in <1991Nov13.194420.28091@netlabs.com>
------------------------------
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 5685
**************************************