[25291] in Perl-Users-Digest
Perl-Users Digest, Issue: 7536 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 19 18:05:40 2004
Date: Sun, 19 Dec 2004 15:05:05 -0800 (PST)
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, 19 Dec 2004 Volume: 10 Number: 7536
Today's topics:
Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/ <please@send.replies.to.ng>
Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/ (Anno Siegel)
Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/ <please@send.replies.to.ng>
Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/ (Anno Siegel)
[ANNOUNCE] wxPerl 0.21 <mbarbon@cpan.org>
Re: Consecutive Numbers <nospam-abuse@ilyaz.org>
Re: Finding out if another copy of a CGI Perl scripts i (Randal L. Schwartz)
Re: Finding out if another copy of a CGI Perl scripts i <flavell@ph.gla.ac.uk>
Re: Finding out if another copy of a CGI Perl scripts i <1usa@llenroc.ude.invalid>
Re: Finding out if another copy of a CGI Perl scripts i <please_post@nomail.edu>
Re: Finding out if another copy of a CGI Perl scripts i (Randal L. Schwartz)
Re: Finding out if another copy of a CGI Perl scripts i <1usa@llenroc.ude.invalid>
Re: Need help with constants and package names. <nobull@mail.com>
Page can not be displayed... (Piet L.)
Page can not be displayed... (Piet L.)
Re: Page can not be displayed... <1usa@llenroc.ude.invalid>
Re: Page can not be displayed... <uri@stemsystems.com>
Perl proxy chaining script fdsjksdk@linuxmail.org
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 19 Dec 2004 16:43:16 +0000 (UTC)
From: Mike <please@send.replies.to.ng>
Subject: Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/
Message-Id: <cq4b34$h2t$1@reader2.panix.com>
In <cq4450$bvr$1@mamenchi.zrz.TU-Berlin.DE> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>Mike <please@send.replies.to.ng> wrote in comp.lang.perl.misc:
>>
>> I want a regexp that will match (as a "whole word") any of the
>> (non-empty) prefixes of the word "foobar", i.e. "f", "fo", "foo",
>> "foob", etc. One way to do it is this:
>>
>> /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/
>>
>> Yuk. Is there a better way?
>Yuk is in the eye of the beholder.
>The regex isn't particularly readable, but it *is* an economical way
>to match all possible prefixes, as opposed to the readable but
>repetitive
> /\b(?:foobar|fooba|foob|foo|fo|f)\b/
>If the pattern is generated by a well-named routine, readability of
>the result doesn't matter much:
> sub prefix_pattern {
> my $pat = '';
> # build innermost pattern first
> $pat = "(?:$_$pat)?" for reverse split //, shift;
> $pat;
> }
> my $re = prefix_pattern( $word);
> print join( ", ", 'X f YY foob ZZZ foobar' =~ /\b$re\b/g), "\n";
>This prints a lot of comma-separated empty strings because it also matches
>the empty prefix. The first character is made optional like the rest of
>them. To amend this, treat the first character extra. Using the same
>prefix_pattern():
> my ( $first, $rest) = $word =~ /(.)(.*)/ or die "Word can't be empty";
> my $re = $first . prefix_pattern( $rest);
> print join( ", ", 'X f YY foob ZZZ foobar' =~ /\b$re\b/g), "\n";
That's cool. But I'm curious, why did you design prefix_pattern
to make also the first letter optional? My naive implementation
of prefix_pattern would have treated the first letter specially:
sub my_prefix_pattern {
my ($first, $rest) = split //, shift, 2;
$first . ($rest ? '(?:' . my_prefix_pattern($rest) . ')?' : '');
}
After all, in the rare instances in which one wanted to treat even
the first letter as optional, one could still easily define $re as
my $re = '(?:' . my_prefix_pattern($word) . ')?';
Mike
------------------------------
Date: 19 Dec 2004 18:02:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/
Message-Id: <cq4fo4$hus$1@mamenchi.zrz.TU-Berlin.DE>
Mike <please@send.replies.to.ng> wrote in comp.lang.perl.misc:
> In <cq4450$bvr$1@mamenchi.zrz.TU-Berlin.DE>
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
> >Mike <please@send.replies.to.ng> wrote in comp.lang.perl.misc:
> >>
> >> I want a regexp that will match (as a "whole word") any of the
> >> (non-empty) prefixes of the word "foobar", i.e. "f", "fo", "foo",
> >> "foob", etc. One way to do it is this:
> >>
> >> /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/
> >>
> >> Yuk. Is there a better way?
>
> >Yuk is in the eye of the beholder.
>
> >The regex isn't particularly readable, but it *is* an economical way
> >to match all possible prefixes, as opposed to the readable but
> >repetitive
>
> > /\b(?:foobar|fooba|foob|foo|fo|f)\b/
>
> >If the pattern is generated by a well-named routine, readability of
> >the result doesn't matter much:
>
> > sub prefix_pattern {
> > my $pat = '';
> > # build innermost pattern first
> > $pat = "(?:$_$pat)?" for reverse split //, shift;
> > $pat;
> > }
>
> > my $re = prefix_pattern( $word);
> > print join( ", ", 'X f YY foob ZZZ foobar' =~ /\b$re\b/g), "\n";
>
> >This prints a lot of comma-separated empty strings because it also matches
> >the empty prefix. The first character is made optional like the rest of
> >them. To amend this, treat the first character extra. Using the same
> >prefix_pattern():
>
> > my ( $first, $rest) = $word =~ /(.)(.*)/ or die "Word can't be empty";
> > my $re = $first . prefix_pattern( $rest);
> > print join( ", ", 'X f YY foob ZZZ foobar' =~ /\b$re\b/g), "\n";
>
>
> That's cool. But I'm curious, why did you design prefix_pattern
> to make also the first letter optional? My naive implementation
> of prefix_pattern would have treated the first letter specially:
>
> sub my_prefix_pattern {
> my ($first, $rest) = split //, shift, 2;
> $first . ($rest ? '(?:' . my_prefix_pattern($rest) . ')?' : '');
> }
That's a possibility, though I tend to avoid recursion when it doesn't
have a clear advantage. Maybe it has, I haven't tried to rewrite it.
However, there's a general design principle that says a subroutine
should do one thing right, no more, no less. As a corollary, in a
well-written program every subroutine does almost nothing. :) This
makes as sub easy to describe and to remember what it does, and it
makes it well suited as a building block, even if the expected usage
changes later.
When writing a sub to do X, there is often a temptation to say, I'll
never want X without Y in this program, so let's put Y in there, too.
It looks economical. However, I have often (and too often painfully)
reversed that kind of decision, so I tend to keep dealing with special
cases out of subroutines.
Taken a step further, I might even pull split( //, ...) out of the sub
and relegate it to the caller. Let the user provide a list of arbitrary
strings (which will be single characters in the actual calls).
sub prefix_pattern {
my $pat = ''
$pat = "(?:$_$pat)?" for reverse @_;
$pat;
}
(The sub name needs some thought now.)
> After all, in the rare instances in which one wanted to treat even
> the first letter as optional, one could still easily define $re as
How do you know they will always be rare? The empty string *is* a
legitimate prefix, after all. I often find, when I refine an ad-hoc
solution to a more systematic approach, the limiting and special cases
are dealt with quite differently than anticipated. Then it's good when
they aren't hard-soldered into the basic routines.
> my $re = '(?:' . my_prefix_pattern($word) . ')?';
Yes, but you are fixing a result to fit the general case because it is
too special. It is better to fix the general result to fit the special
case.
All that said, in the concrete example the issue is minor. If you
*know* you'll never want the empty prefix to match, go ahead and
write a sub to that specification. I just took occasion to apply
the more general principle.
Anno
------------------------------
Date: Sun, 19 Dec 2004 19:09:30 +0000 (UTC)
From: Mike <please@send.replies.to.ng>
Subject: Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/
Message-Id: <cq4jla$jkv$1@reader2.panix.com>
In <cq4fo4$hus$1@mamenchi.zrz.TU-Berlin.DE> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>Mike <please@send.replies.to.ng> wrote in comp.lang.perl.misc:
>> In <cq4450$bvr$1@mamenchi.zrz.TU-Berlin.DE>
>> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>>
>> >Mike <please@send.replies.to.ng> wrote in comp.lang.perl.misc:
>> >>
>> >> I want a regexp that will match (as a "whole word") any of the
>> >> (non-empty) prefixes of the word "foobar", i.e. "f", "fo", "foo",
>> >> "foob", etc. One way to do it is this:
>> >>
>> >> /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/
>> >>
>> >> Yuk. Is there a better way?
>>
>> >Yuk is in the eye of the beholder.
>>
>> >The regex isn't particularly readable, but it *is* an economical way
>> >to match all possible prefixes, as opposed to the readable but
>> >repetitive
>>
>> > /\b(?:foobar|fooba|foob|foo|fo|f)\b/
>>
>> >If the pattern is generated by a well-named routine, readability of
>> >the result doesn't matter much:
>>
>> > sub prefix_pattern {
>> > my $pat = '';
>> > # build innermost pattern first
>> > $pat = "(?:$_$pat)?" for reverse split //, shift;
>> > $pat;
>> > }
>>
>> > my $re = prefix_pattern( $word);
>> > print join( ", ", 'X f YY foob ZZZ foobar' =~ /\b$re\b/g), "\n";
>>
>> >This prints a lot of comma-separated empty strings because it also matches
>> >the empty prefix. The first character is made optional like the rest of
>> >them. To amend this, treat the first character extra. Using the same
>> >prefix_pattern():
>>
>> > my ( $first, $rest) = $word =~ /(.)(.*)/ or die "Word can't be empty";
>> > my $re = $first . prefix_pattern( $rest);
>> > print join( ", ", 'X f YY foob ZZZ foobar' =~ /\b$re\b/g), "\n";
>>
>>
>> That's cool. But I'm curious, why did you design prefix_pattern
>> to make also the first letter optional? My naive implementation
>> of prefix_pattern would have treated the first letter specially:
>>
>> sub my_prefix_pattern {
>> my ($first, $rest) = split //, shift, 2;
>> $first . ($rest ? '(?:' . my_prefix_pattern($rest) . ')?' : '');
>> }
>That's a possibility, though I tend to avoid recursion when it doesn't
>have a clear advantage. Maybe it has, I haven't tried to rewrite it.
I admit it, I'm a bit of a recursion junkie...
>However, there's a general design principle that says a subroutine
>should do one thing right, no more, no less. As a corollary, in a
>well-written program every subroutine does almost nothing. :) This
>makes as sub easy to describe and to remember what it does, and it
>makes it well suited as a building block, even if the expected usage
>changes later.
Thanks, this is very helpful. Design issues like this one are the
aspect of programming I have the hardest time with.
Mike
------------------------------
Date: 19 Dec 2004 21:43:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: /\bf(?:o(?:o(?:b(?:a(?:r)?)?)?)?)?\b/
Message-Id: <cq4sm6$ofq$1@mamenchi.zrz.TU-Berlin.DE>
Mike <please@send.replies.to.ng> wrote in comp.lang.perl.misc:
> In <cq4fo4$hus$1@mamenchi.zrz.TU-Berlin.DE>
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
[lots]
> >However, there's a general design principle that says a subroutine
> >should do one thing right, no more, no less. As a corollary, in a
> >well-written program every subroutine does almost nothing. :) This
> >makes as sub easy to describe and to remember what it does, and it
> >makes it well suited as a building block, even if the expected usage
> >changes later.
>
> Thanks, this is very helpful. Design issues like this one are the
> aspect of programming I have the hardest time with.
Me too.
Anno
------------------------------
Date: Sun, 19 Dec 2004 16:43:28 GMT
From: Mattia Barbon <mbarbon@cpan.org>
Subject: [ANNOUNCE] wxPerl 0.21
Message-Id: <Xns95C4B48C2DD14mbarboncpanorg@193.70.192.192>
A new version of wxPerl, the Perl bindings to wxWindows, is out!
wxWindows is a free and cross platform (Windows/Motif/GTK/Mac) C++ GUI
toolkit with native look and feel. (visit http://www.wxwindows.org/
for details).
You can download wxPerl sources from
$CPAN/authors/id/M/MB/MBARBON/Wx-0.21.tar.gz;
Screenshots: http://wxperl.sourceforge.net/sshot01.html
Binary packages for ActivePerl/Win32 6xx and 8xx builds, and Red Hat
Linux are available along with documentation in HTML and MS HTML Help
format from http://wxperl.sourceforge.net/download.html
The project home page is http://wxperl.sourceforge.net/. There is also
a mailing list dedicated to wxPerl users:
wxperl-users@lists.sourceforge.net
Changes since the last release:
- Fixed installation of 'wxPerl' command on Mac OS X.
- Fixed running in the embedded case (still requires the
application to call ExitMainLoop at the right places).
- Wrapped wxNavigationKeyEvent.
- Using die() in an event handler should not crash anymore
(it might leak).
- Added Wx::PlWindow, to be used for custom controls.
- New (Windows-only) --mslu flag for Makefile.PL.
- Wx::NotebookSizer is now no longer needed and
deprecated.
Regards
Mattia
------------------------------
Date: Sun, 19 Dec 2004 21:45:31 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Consecutive Numbers
Message-Id: <cq4spr$eqg$1@agate.berkeley.edu>
[A complimentary Cc of this posting was NOT [per weedlist] sent to
Ilya Zakharevich
<nospam-abuse@ilyaz.org>], who wrote in article <cpifp9$qjh$1@agate.berkeley.edu>:
> [A complimentary Cc of this posting was NOT [per weedlist] sent to
> Graham Drabble
> <graham.drabble@lineone.net>], who wrote in article <Xns95BDB5D279355grahamdrabblelineone@ID-77355.user.dfncis.de>:
> > I have a file that contains a list of numbers. I'm trying to process
> > the file to find out how many rows start with 4 consecutive digits
> > (either ascending or decending). Currently I've got
>
> I'm puzzled at all complications: what is wrong with using something like
>
> my $four = substr $in, 0, 4;
> print 'OK' if length $four == 4 and
> (0 <= index '0123456789', $four or 0 <= index '9876543210', $four);
Or one can try something like
my $four = substr $in, 0, 4;
print 'OK' if length $four == 4 and
0 <= index "0123456789\x{FFFFFFFF}9876543210", $four;
for its speed. However, the Unicode overhead can eat the advantages
of fewer opcodes to dispatch...
Yours,
Ilya
P.S. Here I use the fact that utf8 character repertuar is larger than
UTF-8 one.
------------------------------
Date: 19 Dec 2004 08:21:13 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <1103474013.9a3150ae617322252d0cd808fb1bea1a@teranews>
>>>>> "Lisa" == Lisa <dlr93612@yahoo.com> writes:
Lisa> How would one go about finding out if another copy of a CGI Perl
Lisa> scripts is running?
Lisa> I want to set up a script to run as a cron job, starting about once a
Lisa> minute, however, the first thing I want to do when the script starts is
Lisa> to check and see if the last incarnation is still (highly unlikly but
Lisa> could happen on very busy days) running and shut down if it is, so that
Lisa> there is only one version of the script proccessing data.
See "There can be only one! - The Highlander solution" at
<http://www.stonehenge.com/merlyn/WebTechniques/col54.html>.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sun, 19 Dec 2004 17:11:51 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <Pine.LNX.4.61.0412191700220.30690@ppepc56.ph.gla.ac.uk>
On Sun, 19 Dec 2004, KKramsch wrote:
[..]
> > open my $lock, '>', 'lockfile'
> > or die "Cannot open lockfile: $!";
> > flock $lock, LOCK_EX
> > or die "Cannot obtain exclusive lock on lockfile: $!";
>
> One thing that confuses me about this code is that whether flock
> succeeds or not, lockfile gets clobbered by the open.
In *this* particular scheme, the lockfile exists solely for the
purpose of getting a lock put on it. Its contents are irrelevant.
*If* one is trying to get an exclusive lock on an actual data file,
then it might be more useful and obvious if the lock was put on the
data file itself, than to create some auxiliary file to hold the lock.
And then you'd look for an alternative strategy for doing the open,
indeed.
The lockfile technique is more often used when trying to implement
exclusive access to some /other/ resource than a file.
Does that help a bit?
> The lock is "advisory"; it does not block the open.
Correct.
> I think this may be why
> the docs use sysopen with O_RDWR instead of open $fh, ">file":
If you want to put a lock on a data file, then indeed that's
a good approach
> sysopen my $lock, 'lockfile', O_RDWR|O_CREAT
> or die "Can't open lockfile: $!\n";
OK, but this could be your actual data file.
Or perhaps open for append ('>>') , depending on what the process
intends to do with the file once it's got it.
> # I suppose the sysopen above could be replaced with
> # open my $lock, '+<lockfile'
If the file doesn't already exist, then that's going to fail. So,
unlike the other techniques, this one isn't self-starting - someone
has got to create an initial (maybe empty) file before the circus can
begin.
And of course all of the above are going to be reliant on just what
is supported by the particular OS. AIUI some are a bit more portable
between OSes than others.
hth
------------------------------
Date: 19 Dec 2004 17:25:05 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <Xns95C47E531FFFasu1cornelledu@132.236.56.8>
KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid> wrote in
news:cq45es$fcb$1@reader2.panix.com:
> In <Xns95C41E095AAF9asu1cornelledu@132.236.56.8> "A. Sinan Unur"
> <1usa@llenroc.ude.invalid> writes:
>>Other suggested reading:
>
>>http://tinyurl.com/6q2gc
>
>
> In this post you propose the following:
>
>> use Fcntl qw(:flock);
>>
>> sub update {
>>
>> # ...
>>
>> open my $lock, '>', 'lockfile'
>> or die "Cannot open lockfile: $!";
>> flock $lock, LOCK_EX
>> or die "Cannot obtain exclusive lock on lockfile: $!";
>>
>> # Do the updating etc.
>>
>> }
>
> One thing that confuses me about this code is that whether flock
> succeeds or not, lockfile gets clobbered by the open.
I should clarify. The lock file in the code above is meant to be used as a
sentinel to see if it is OK to update the actual data file one is
interested in. One would only open the data file in the
# Do the updating etc
section. Of course, the OP would check if the exclusive lock succeeded and
return from the sub if it did not.
Sinan.
------------------------------
Date: Sun, 19 Dec 2004 17:26:40 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <cq4dkg$hse$1@reader2.panix.com>
In <1103474013.9a3150ae617322252d0cd808fb1bea1a@teranews> merlyn@stonehenge.com (Randal L. Schwartz) writes:
>See "There can be only one! - The Highlander solution" at
><http://www.stonehenge.com/merlyn/WebTechniques/col54.html>.
which has the following:
=7= my $count = 0;
=8= {
=9= flock HIGHLANDER, LOCK_EX | LOCK_NB and last;
=10= sleep 1;
=11= redo if ++$count < 10;
> Line 11 increments count, and ensures that it is still below 10.
> If so, the redo operator pops back up to line 8, retrying the flock.
> If not, we've tried 10 times to flock, or ur, actually, 9 times to
> flock (durn fencepost off-by-one errors!), and it's time to report
> the error.
Maybe I'm missing something but I think your code is right (no
off-by-one error: it tries flock at most 10 times). It's easy to
see if you change the "10" on line 11 to "1" or "2".
bill
------------------------------
Date: 19 Dec 2004 09:39:49 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <1103478501.ab254373dcf5b3c802af0f73dee4d953@teranews>
>>>>> "bill" == bill <please_post@nomail.edu> writes:
bill> In <1103474013.9a3150ae617322252d0cd808fb1bea1a@teranews> merlyn@stonehenge.com (Randal L. Schwartz) writes:
>> See "There can be only one! - The Highlander solution" at
>> <http://www.stonehenge.com/merlyn/WebTechniques/col54.html>.
bill> which has the following:
bill> =7= my $count = 0;
bill> =8= {
bill> =9= flock HIGHLANDER, LOCK_EX | LOCK_NB and last;
bill> =10= sleep 1;
bill> =11= redo if ++$count < 10;
>> Line 11 increments count, and ensures that it is still below 10.
>> If so, the redo operator pops back up to line 8, retrying the flock.
>> If not, we've tried 10 times to flock, or ur, actually, 9 times to
>> flock (durn fencepost off-by-one errors!), and it's time to report
>> the error.
bill> Maybe I'm missing something but I think your code is right (no
bill> off-by-one error: it tries flock at most 10 times). It's easy to
bill> see if you change the "10" on line 11 to "1" or "2".
Well, it's counting how many times it *had* tried, and only redoes
it if it's less than 10. Oh, so on the 10th time, it bails out.
OK, looks like I get an A for coding, and an F for figuring out
what my code did. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 19 Dec 2004 18:19:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <Xns95C4879A26186asu1cornelledu@132.236.56.8>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns95C47E531FFFasu1cornelledu@132.236.56.8:
> KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid> wrote in
> news:cq45es$fcb$1@reader2.panix.com:
>
>> In <Xns95C41E095AAF9asu1cornelledu@132.236.56.8> "A. Sinan Unur"
>> <1usa@llenroc.ude.invalid> writes:
>>>Other suggested reading:
>>
>>>http://tinyurl.com/6q2gc
>>
>> In this post you propose the following:
>>
>>> use Fcntl qw(:flock);
>>>
>>> sub update {
>>>
>>> # ...
>>>
>>> open my $lock, '>', 'lockfile'
>>> or die "Cannot open lockfile: $!";
>>> flock $lock, LOCK_EX
>>> or die "Cannot obtain exclusive lock on lockfile: $!";
>>>
>>> # Do the updating etc.
>>>
>>> }
>>
>> One thing that confuses me about this code is that whether flock
>> succeeds or not, lockfile gets clobbered by the open.
>
> I should clarify. The lock file in the code above is meant to be used
> as a sentinel to see if it is OK to update the actual data file one is
> interested in. One would only open the data file in the
>
> # Do the updating etc
>
> section. Of course, the OP would check if the exclusive lock succeeded
> and return from the sub if it did not.
Probably by doing (untested):
flock $lock, LOCK_EX|LOCK_NB or return;
Please also see Randal Schwartz's post. After all, I learned a lot of what
little I know about Perl from his columns.
Sinan
------------------------------
Date: Sun, 19 Dec 2004 16:38:26 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Need help with constants and package names.
Message-Id: <cq4aq5$ib6$1@slavica.ukpost.com>
Ben Morrow wrote:
> Quoth Brian McCauley <nobull@mail.com>:
>
>>Sherm Pendley wrote:
>>
>>>Terry wrote:
>>>
>>>
>>>>Something I didn't find in the perldoc was how to export a hash using
>>>>the 'use constant' pragma.
>
> <snip>
>
>>It works just fine if you pay proper attension to run-time v.
>>compile-time issues.
>>
>>
>>>I haven't found a way to do that either - and believe me I've tried.
>>
>>BEGIN {
>> my %constants = (
>> one => 1 ,
>> two => 2 ,
>> # ...
>> );
>> require constants;
>> import constants %constants;
>> push @EXPORT => keys %constants;
>>}
>
>
> That BEGIN is unnecessary if there is no other code in the file: the
> require is happening at BEGIN time anyway, and before import is called.
>
> If there *is* other code in the file, it won't have access to the
> constants.
How do you figure that?
There were several mistakes in my code but that wasn't one of them. The
two lines...
require constants;
import constants %constants;
...should have read...
require constant;
import constant $_ => $constants{$_} for keys %constants;
...and then the code beyond the BEGIN block _can_ access the the constants.
------------------------------
Date: 19 Dec 2004 11:13:49 -0800
From: PietLaroy@hotmail.com (Piet L.)
Subject: Page can not be displayed...
Message-Id: <c47f81f6.0412191113.64d05a9e@posting.google.com>
Ok, but how do I do this?
You've seen the code.
------------------------------
Date: 19 Dec 2004 12:02:15 -0800
From: PietLaroy@hotmail.com (Piet L.)
Subject: Page can not be displayed...
Message-Id: <c47f81f6.0412191202.78e7d464@posting.google.com>
the actual error is: The server can not be found or DNS error Internet Explorer
------------------------------
Date: 19 Dec 2004 19:17:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Page can not be displayed...
Message-Id: <Xns95C4917133AACasu1cornelledu@132.236.56.8>
PietLaroy@hotmail.com (Piet L.) wrote in
news:c47f81f6.0412191113.64d05a9e@posting.google.com:
> Ok, but how do I do this?
> You've seen the code.
>
No we haven't.
Post replies in the same thread. Quote context. Etc.
perldoc -q 500
Sinan
------------------------------
Date: Sun, 19 Dec 2004 20:13:20 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Page can not be displayed...
Message-Id: <x7llbu11y8.fsf@mail.sysarch.com>
>>>>> "PL" == Piet L <PietLaroy@hotmail.com> writes:
PL> the actual error is: The server can not be found or DNS error
PL> Internet Explorer
jeez, can't you figure out what that means? it means you can't find the
server. duh! it has nothing to do with perl, nothing to do with the cgi,
nothing to do with the server code, nothing to do with your browser.
it probably means you TYPED in the WRONG hostname. but you couldn't have
figured that out from that error message, could you?
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 19 Dec 2004 09:58:46 -0800
From: fdsjksdk@linuxmail.org
Subject: Perl proxy chaining script
Message-Id: <1103479126.066718.101230@c13g2000cwb.googlegroups.com>
I'm looking for a Perl script that can chain proxies together. Can
this be done in Perl?
I know Perl can do proxy requests with LWP but I can't find any
information on proxy-chaining in Perl.
Any information on this topic will be appreciated. Thanks.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7536
***************************************