[9218] in Perl-Users-Digest
Perl-Users Digest, Issue: 2813 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 8 15:07:11 1998
Date: Mon, 8 Jun 98 12:00:24 -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 Mon, 8 Jun 1998 Volume: 8 Number: 2813
Today's topics:
Re: (1 and '') vs. (1 && '') (Clinton Pierce)
Re: (1 and '') vs. (1 && '') <tchrist@mox.perl.com>
Re: (1 and '') vs. (1 && '') <bowlin@sirius.com>
Re: (1 and '') vs. (1 && '') (Matt Knecht)
Re: (1 and '') vs. (1 && '') (Todd Lehman)
Re: Day of Week Display for User-defined date <kcl@mindspring.com>
Re: Field order from a Web Server <kmiles@erols.com>
Found it (was Re: Preventing file conflicts) <jgoldberg@dial-but-dont-spam.pipex.com>
Re: offline mode? (Andy Finkenstadt)
Passing arguements to interactive shell commands <jnoviell@matrox.com>
Re: Preventing file conflicts <zenin@bawdycaste.org>
Re: Preventing file conflicts <tchrist@mox.perl.com>
Re: Preventing file conflicts <jgoldberg@dial-but-dont-spam.pipex.com>
Re: Preventing file conflicts <jgoldberg@dial-but-dont-spam.pipex.com>
Re: RECOMMEND A PERL BOOK/RESOURCES ?? <barnett@houston.Geco-Prakla.slb.com>
Re: Skipping iterations in while <tchrist@mox.perl.com>
Re: Skipping iterations in while (Mark-Jason Dominus)
substitution not working <probavm@cat.com>
Substr <ragunkel@att.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 Jun 1998 17:38:36 GMT
From: cpierce1@cp500.fsic.ford.com (Clinton Pierce)
To: lehman@visi.com (Todd Lehman)
Subject: Re: (1 and '') vs. (1 && '')
Message-Id: <6lh7is$h2a2@eccws1.dearborn.ford.com>
In article <TcVe1.282$bj2.1592639@ptah.visi.com>,
lehman@visi.com (Todd Lehman) writes:
>
>Am I high, or should (1 and '') evaluate to ''?
>
>I've been using '&&' and 'and' interchangably for a long time, except for
>cosmetic/readability differentiations, until today when I hit something
>very unexpected. Here's a short program to demonstreate what I don't get:
>
>
>----begin freakmeout.pl----
>use strict;
>$^W = 1;
>
>my $x = 1 and '';
>my $y = 1 && '';
>
>print "x = ", $x? 'true':'false', "\n";
>print "y = ", $y? 'true':'false', "\n";
>----end freakmeout.pl----
>
>
>Blue Camel page 94 says: "As more readable alternatives to &&, ||, and
>!, Perl provides the and, or and not operators. The behavior of these
>operators is identical--in particular, they short-circuit the same way."
>
>I ran the above program under 5.003_00, 5.004_00, 5.004_01, and 5.004_02.
>Same result. Why is $x equal to 1? What am I not getting?
You stopped reading too soon...." they short-circut the same way. The
precedence of these operators is much lower, however..."
Go back and read page 76 of the Blue Camel where precedence is explained.
What's biting you is that && has higher precedence than = which has higher
precedence than "and". So:
$x = 1 and ''; # is the same as: ( $x = 1 ) && '';
..whereas...
$x = 1 && ''; # is the same as: $x = ( 1 && '');
What you really want to say is:
$x = (1 and '');
That'll give ya what ya want!
--
+------------------------------------------------------------------------+
| Clinton A. Pierce | "If you rush a Miracle Man, | http://www. |
| cpierce1@ford.com | you get rotten miracles" | dcicorp.com/ |
| fubar@ameritech.net |--Miracle Max, The Princess Bride| ~clintp |
+------------------------------------------------------------------------+
GCSd-s+:+a-C++UALIS++++P+++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*
------------------------------
Date: 8 Jun 1998 17:49:02 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: (1 and '') vs. (1 && '')
Message-Id: <6lh86e$efo$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
lehman@visi.com (Todd Lehman) writes:
:Am I high, or should (1 and '') evaluate to ''?
It does.
:I've been using '&&' and 'and' interchangably for a long time,
: my $x = 1 and '';
: my $y = 1 && '';
+---------------+
| +-----------+ |
| | STOP THAT | |
| +-----------+ |
+---------------+
They are not interchangeable. You've forgotten precedence. Here's a
tip: use "and" and "or" when you mean flow-control *only*--if then.
Otherwise, use the normal operators. They stand out better.
Here are some excerpts from the perlop manpage for the
imminent 5.005 release:
=head2 C-style Logical Or
Binary "||" performs a short-circuit logical OR operation. That is,
if the left operand is true, the right operand is not even evaluated.
Scalar or list context propagates down to the right operand if it
is evaluated.
The C<||> and C<&&> operators differ from C's in that, rather than
returning 0 or 1, they return the last value evaluated. Thus,
a reasonably portable way to find out the home directory (assuming
it's not "0") might be:
$home = $ENV{'HOME'} || $ENV{'LOGDIR'} ||
(getpwuid($<))[7] || die "You're homeless!\n";
In particular, this means that you shouldn't use this
for selecting between two aggregates for assignment:
@a = @b || @c; # this is WRONG (context)
@a = scalar(@b) || @c; # really meant this
@a = @b ? @b : @c; # this works fine, though
As more readable alternatives to C<&&> and C<||> when used for
control flow, Perl provides "and" and "or" operators (see below).
The short-circuit behavior is identical. The precedence of "and"
and "or" is much lower, however, so that you can safely use them
after a list operator without the need for parentheses:
unlink "alpha", "beta", "gamma"
or gripe(), next LINE;
With the C-style operators that would have been written like this:
unlink("alpha", "beta", "gamma")
|| (gripe(), next LINE);
Using "and" or "or" for assignment is unlikely to do what you want;
see below.
[.....]
=head2 Logical or and Exclusive Or
Binary "or" returns the logical disjunction of the two surrounding
expressions. It's equivalent to || except for the very low
precedence. This makes it useful for control flow
print FH $data or die "Can't write to FH: $!";
This means that it short-circuits: i.e., the right expression
is evaluated only if the left expression is false. Due to its
precedence, you should probably avoid using this for assignment,
only for control flow.
$a = $b or $c; # bug: this is WRONG (prececence)
($a = $b) or $c; # really means this
$a = $b || $c; # better written this way
However, when it's a list context assignment and you're trying to use
"||" for control flow, you probably need "or" so that the assignment
takes higher precedence.
@info = stat($file) || die; # oops, scalar sense of stat!
@info = stat($file) or die; # better, now @info gets its due
Then again, you could always use parentheses.
--tom
--
It won't be covered in the book. The source code has to be useful for
something, after all... :-)
--Larry Wall in <10160@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Mon, 08 Jun 1998 10:58:24 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: Todd Lehman <lehman@visi.com>
Subject: Re: (1 and '') vs. (1 && '')
Message-Id: <357C2640.491A0860@sirius.com>
Todd Lehman wrote:
>
> Am I high, or should (1 and '') evaluate to ''?
>
> I've been using '&&' and 'and' interchangably for a long time, except for
> cosmetic/readability differentiations, until today when I hit something
> very unexpected. Here's a short program to demonstreate what I don't get:
>
> ----begin freakmeout.pl----
> use strict;
> $^W = 1;
>
> my $x = 1 and '';
> my $y = 1 && '';
>
> print "x = ", $x? 'true':'false', "\n";
> print "y = ", $y? 'true':'false', "\n";
> ----end freakmeout.pl----
>
> Blue Camel page 94 says: "As more readable alternatives to &&, ||, and
> !, Perl provides the and, or and not operators. The behavior of these
> operators is identical--in particular, they short-circuit the same way."
There is a difference in operator precedence. Take a look at the table
in Blue Camel pp. 76-77. You will see that the precedence of the 'and',
'or' operators is lower than the assignment operators. This is very
handy in many situations such as:
my $x = some_function() or die "trying ...";
or even
my $x = $a || $b || $c or die "trying ...";
For this reason, I tend to use 'and' and 'or' for control flow, while
I use '&&' and '||' to set default values of variables.
HTH - Jim Bowlin
------------------------------
Date: Mon, 08 Jun 1998 18:12:55 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: (1 and '') vs. (1 && '')
Message-Id: <HQVe1.925$14.5018627@news2.voicenet.com>
Todd Lehman <lehman@visi.com> wrote:
>I've been using '&&' and 'and' interchangably for a long time, except for
>cosmetic/readability differentiations, until today when I hit something
>very unexpected. Here's a short program to demonstreate what I don't get:
I recently had a very similar problem solved here. It's a precedence
problem. To see the thread check out dejanews with this as your search:
'~g comp.lang.perl.misc ~s list context' (The subject is, specifically
'list context: || vs or').
>my $x = 1 and '';
>my $y = 1 && '';
This is _really_ what you wrote:
($x = 1) and '';
$y = (1 && '');
Easy to see what going on with the parentheses, huh? In fact, with the
parentheses there, you actually can use the operators '&& and'
interchangebly.
>Blue Camel page 94 says: "As more readable alternatives to &&, ||, and
>!, Perl provides the and, or and not operators. The behavior of these
>operators is identical--in particular, they short-circuit the same way."
You left out the next paragraph, which explains it all:
"The precedence of these operators is much lower, however, so you can
safely use them after a list operator without the need for parentheses:
..."
The tricky thing (At least for me) was figuring out that '=' has a higher
precedence than the operators 'or and not'.
As Tom Christiansen so elegantly put it to me: "There is no workaround
for not grokking precedence." I think of this almost every time I write
a line of code that has an operator in it (Which, as you can imagine, is
quite often.).
--
Matt Knecht - <hex@voicenet.com>
"496620796F752063616E207265616420746869732C20796F7520686176652066
617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"
------------------------------
Date: Mon, 08 Jun 1998 18:22:49 GMT
From: lehman@visi.com (Todd Lehman)
Subject: Re: (1 and '') vs. (1 && '')
Message-Id: <ZZVe1.292$bj2.1623259@ptah.visi.com>
In article <TcVe1.282$bj2.1592639@ptah.visi.com>,
Todd Lehman <lehman@visi.com> wrote:
>
> Am I high, or should (1 and '') evaluate to ''?
Both, apparently. :-) Thank god I'm stupid and Perl is not broken. And
thanks to everyone who responded (so quickly, even!).
Doy. D'OH. Duh. Shame on me. Brain = Off. Panic = On. I moved a
perfectly working construct out of an 'if' clause and into a variable
assignment without considering precedence (and I even know full well
about precedence). I shouldn't even have been using 'and' there in the
first place. 'and' and 'or' are much better between statements, not as
substitutes for '&&' and '||'.
my $x = 1 and '';
is not the same as
my $x = (1 and '');
I cancelled my original article so it doesn't waste any more people's time.
OK, duh. Sorry. Tail tucked. Nuff said. Thanks again.
--Todd
> I've been using '&&' and 'and' interchangably for a long time, except for
> cosmetic/readability differentiations, until today when I hit something
> very unexpected. Here's a short program to demonstreate what I don't get:
>
>
> ----begin freakmeout.pl----
> use strict;
> $^W = 1;
>
> my $x = 1 and '';
> my $y = 1 && '';
>
> print "x = ", $x? 'true':'false', "\n";
> print "y = ", $y? 'true':'false', "\n";
> ----end freakmeout.pl----
>
>
> Blue Camel page 94 says: "As more readable alternatives to &&, ||, and
> !, Perl provides the and, or and not operators. The behavior of these
> operators is identical--in particular, they short-circuit the same way."
>
> I ran the above program under 5.003_00, 5.004_00, 5.004_01, and 5.004_02.
> Same result. Why is $x equal to 1? What am I not getting?
>
> --Todd
------------------------------
Date: Mon, 08 Jun 1998 14:41:20 -0400
From: KC Lucchese <kcl@mindspring.com>
Subject: Re: Day of Week Display for User-defined date
Message-Id: <357C3050.3EBE6D1C@mindspring.com>
What a witch. Your trailer park cancel bingo again, honey?
Abigail wrote:
>
> KC Lucchese (kcl@mindspring.com) wrote on MDCCXLII September MCMXCIII in
> <URL: news:357BF02D.977101F2@mindspring.com>:
> ++ Please pardon a question that might have been asked a thousand times
>
> No. Asking such questions is unforgivable; not just about Perl, but
> in any newsgroup. That's what FAQs are for. Read it.
>
> ++ before! I know just enough PERL to be dangerous and to support someone
> ++ else's scripts (which is what I'm doing)...
>
> That is no excuse for not reading the FAQ.
>
> ++ I need to display the day of the week (Sunday, Monday, etc.) for a date
> ++ which the user chooses from a drop-down list.
>
> What have drop-down lists to do with Perl?
>
> ++ Is there a way to do this????
>
> Read the FAQ.
>
> Abigail
> --
> perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
> ${qq$\x5F$} = q 97265646f9 and s g..g;
> qq e\x63\x68\x72\x20\x30\x78$&eggee;
> {eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'
------------------------------
Date: Mon, 08 Jun 1998 14:11:55 -0400
From: Kevin Miles <kmiles@erols.com>
To: Robin Smith <r.d.smith@man0501.wins.icl.co.uk>
Subject: Re: Field order from a Web Server
Message-Id: <357C296A.87C537A1@erols.com>
Robin Smith wrote:
> Does anyone know if it is possible to control/re-arrange the order that
> fields are passed to a perl script. I have a questionaire that has fields
>
> Q1.1, Q1.2, Q1.3, Q2.1, Q2.2, Q2.3 ...etc
>
> The perl script just writes them to a file, and they come out in the order
>
> Q1.1, Q1.2, Q2.1, Q1.3, Q2.2, Q3.1, Q1.4 ...etc
>
> I need them to be in the correct order that they appear in on the form.
> Why are they being changed??
> Use the CGI.pm module included with perl5. It should do what you need, while
> eliminating the need for your parse/decode code.
Kevin Miles
>
>
------------------------------
Date: Mon, 8 Jun 1998 19:50:30 +0100
From: "Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
Subject: Found it (was Re: Preventing file conflicts)
Message-Id: <6lhbrj$h6l$1@soap.news.pipex.net>
> You can try dot locking it. -Creating a $filename.lock file as an
> indicator to the other process that the file is "locked". Remember
> to open the dot lock file in O_EXCL|O_CREAT|O_WRONLY (I think...)
> mode to make sure you don't get a race condition with two processes
> trying to lock at once. See open(2) for details on the flags.
> You can use the flags via perl's sysopen() call and import the flag
> constants from the Fcntl module ("use Fcntl;" get you the O_*
> stuff).
Ignore that last post about (where to find it), I wasn't paying enough
attention...
------------------------------
Date: 8 Jun 1998 14:50:56 -0400
From: kahuna@panix.com (Andy Finkenstadt)
Subject: Re: offline mode?
Message-Id: <6lhbqg$igo@panix3.panix.com>
In <6lfkgh$l18$1@csnews.cs.colorado.edu> Tom Christiansen <tchrist@mox.perl.com> writes:
>In comp.lang.perl.misc, watsons@teleport.com (Linda Watson) writes:
>:I'm just learning perl and cgi.
>I wonder why no one ever posts "I'm just learning C and tcp."
Okay. Having programmed in C and Perl (and many other languages)
for the last 20 years or so, I'm just learning C++ and trying to
apply the tcp knowledge I learned in Perl to it. :-)
Of course, the answer to my non-existent question is that tcp acts
the same under either language. As could a CGI under either
language.
Andy
--
Andrew Finkenstadt (http://www.panix.com/~genie/)
"I know the answer's in there... the server is just too busy."
------------------------------
Date: Mon, 08 Jun 1998 14:03:35 -0400
From: Joe Novielli <jnoviell@matrox.com>
Subject: Passing arguements to interactive shell commands
Message-Id: <357C2776.1D489BFB@matrox.com>
Greetings,
Is there a way I can pass the answers to interactive shell commands from
a PERL script?
e.g.: answering the command "rm -i filename" (interactive removal which
prompts for a "yes" or "no" answer.)
OR the thing I would like to do
e.g.: submitting new web users and their passwords by a PERL CGI script
by executing Apache's "htpasswd" utility.
Thanks
------------------------------
Date: 8 Jun 1998 18:17:53 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Preventing file conflicts
Message-Id: <897330367.335181@thrush.omix.com>
Jeremy Goldberg <jgoldberg@dial-but-dont-spam.pipex.com> wrote:
>snip<
: 1) Don't say to use flock() / fnctl() - I need a platform-independant system
Duh...this is *exactly* what you're looking for through... :-/
Just how platform-independent do you have to be? Unix + Win32, or
the Mac, OS/2, et al systems as well?
You can try dot locking it. -Creating a $filename.lock file as an
indicator to the other process that the file is "locked". Remember
to open the dot lock file in O_EXCL|O_CREAT|O_WRONLY (I think...)
mode to make sure you don't get a race condition with two processes
trying to lock at once. See open(2) for details on the flags.
You can use the flags via perl's sysopen() call and import the flag
constants from the Fcntl module ("use Fcntl;" get you the O_*
stuff).
: 2) Don't say RTFM - I already have, and found nothing.
I can't believe that, although most of it will probably be talking
about flock() and friends.
My advice would be to roll you own "best method" lock function
that first trys flock() etc and if that doesn't work falls back
to dot locking.
--
-Zenin
zenin@archive.rhps.org
------------------------------
Date: 8 Jun 1998 18:33:03 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Preventing file conflicts
Message-Id: <6lhaov$h6k$1@csnews.cs.colorado.edu>
[courtesy cc of this posting DENIED to cited author via email]
In comp.lang.perl.misc,
"Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com> writes:
HOW THE FRICK DO YOU EXPECT ME TO HELP YOU WITH THAT CRAPPY ADDRESS
YOU NIMROD!?????????????????????????????
cat >>spider-food.html
"Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
"Jeremy Goldberg" <jgoldberg@dial.pipex.com>
"Jeremy Goldberg" <jgoldberg@pipex.com>
^D
:I asked about this a while back and got nothing save flames, but I'll try
:again, since I still don't have an answer. How do you _reliably_ open a file
:AFTER another file has finished writing to it? I don't mean in the middle
:(or even before), but AFTER. e.g.
:
:open( HANDLE, ">test.dat" ) || die $!;
:while( <time-consuming-expression> )
:{
: print HANDLE <data>;
:}
open read-write, no trunc.
flock excl.
trunc.
write.
close.
>Don't say to use flock() / fnctl() - I need a platform-independant system
flock() *is* platform-independent. Who told you otherwise?
You should always use it.
--tom
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1998-06-08 12:29 MDT by <tchrist@jhereg.perl.com>.
# Source directory was `/home/tchrist/writings/cookbook'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
# This format requires very little intelligence at unshar time.
# "if test", "echo", "mkdir", and "sed" may be needed.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 252 -rw-r--r-- tlock
# 2484 -rw-r--r-- File/LockDir.pm
#
echo=echo
if mkdir _sh26705; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= tlock ==============
if test -f 'tlock' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'tlock' '(file already exists)'
else
$echo 'x -' extracting 'tlock' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'tlock' &&
X#!/usr/bin/perl -w
Xuse strict;
X
Xuse File::NetLock;
X
X$SIG{INT} = sub { die "outta here\n" };
X
X$File::NetLock::Debug = 1;
X
Xmy $path = shift || die;
X
Xunless (nflock($path, 2)) {
X die "couldn't lock $path in 2 seconds\n";
X}
Xsleep 100;
Xnunflock($path);
SHAR_EOF
: || $echo 'restore of' 'tlock' 'failed'
fi
# ============= File/LockDir.pm ==============
if test ! -d 'File'; then
$echo 'x -' 'creating directory' 'File'
mkdir 'File'
fi
if test -f 'File/LockDir.pm' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'File/LockDir.pm' '(file already exists)'
else
$echo 'x -' extracting 'File/LockDir.pm' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'File/LockDir.pm' &&
Xpackage File::LockDir;
X
X# module to provide very basic filename-level
X# locks. No fancy systems calls. In theory,
X# directory info is sync'd over NFS. Not
X# stress tested.
X
Xuse strict;
X
Xuse Exporter;
Xuse vars qw(@ISA @EXPORT);
X@ISA = qw(Exporter);
X@EXPORT = qw(nflock nunflock);
X
Xuse vars qw($Debug $Check);
X$Debug ||= 0; # may be predefined
X$Check ||= 5; # may be predefined
X
Xuse Cwd;
Xuse Fcntl;
Xuse Sys::Hostname;
Xuse File::Basename;
Xuse File::stat;
Xuse Carp;
X
Xmy %Locked_Files = ();
X
X# usage: nflock(FILE; NAPTILL)
Xsub nflock($;$) {
X my $pathname = shift;
X my $naptime = shift || 0;
X my $lockname = name2lock($pathname);
X my $whosegot = "$lockname/owner";
X my $start = time();
X my $missed = 0;
X local *OWNER;
X
X # if locking what I've already locked, return
X if ($Locked_Files{$pathname}) {
X carp "$pathname already locked";
X return 1
X }
X
X if (!-w dirname($pathname)) {
X croak "can't write to directory of $pathname";
X }
X
X while (1) {
X last if mkdir($lockname, 0777);
X confess "can't get $lockname: $!" if $missed++ > 10
X && !-d $lockname;
X if ($Debug) {{
X open(OWNER, "< $whosegot") || last; # exit "if"!
X my $lockee = <OWNER>;
X chomp($lockee);
X printf STDERR "%s $0\[$$]: lock on %s held by %s\n",
X scalar(localtime), $pathname, $lockee;
X close OWNER;
X }}
X sleep $Check;
X return if $naptime && time > $start+$naptime;
X }
X sysopen(OWNER, $whosegot, O_WRONLY|O_CREAT|O_EXCL)
X or croak "can't create $whosegot: $!";
X printf OWNER "$0\[$$] on %s since %s\n",
X hostname(), scalar(localtime);
X close(OWNER) or croak "close $whosegot: $!";
X $Locked_Files{$pathname}++;
X return 1;
X}
X
X# free the locked file
Xsub nunflock($) {
X my $pathname = shift;
X my $lockname = name2lock($pathname);
X my $whosegot = "$lockname/owner";
X unlink($whosegot);
X carp "releasing lock on $lockname" if $Debug;
X delete $Locked_Files{$pathname};
X return rmdir($lockname);
X}
X
X# helper function
Xsub name2lock($) {
X my $pathname = shift;
X my $dir = dirname($pathname);
X my $file = basename($pathname);
X $dir = getcwd() if $dir eq '.';
X my $lockname = "$dir/$file.LOCKDIR";
X return $lockname;
X}
X
X
X# anything forgotten?
XEND {
X for my $pathname (keys %Locked_Files) {
X my $lockname = name2lock($pathname);
X my $whosegot = "$lockname/owner";
X carp "releasing forgotten $lockname";
X unlink($whosegot);
X return rmdir($lockname);
X }
X
X}
X
X1;
SHAR_EOF
: || $echo 'restore of' 'File/LockDir.pm' 'failed'
fi
rm -fr _sh26705
exit 0
--
"They'll get my perl when they pry it from my cold, dead /usr/local/bin."
Randy Futor in <1992Sep13.175035.5623@tc.fluke.COM>
------------------------------
Date: Mon, 8 Jun 1998 19:47:59 +0100
From: "Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
Subject: Re: Preventing file conflicts
Message-Id: <6lhbmr$gv1$1@soap.news.pipex.net>
> Duh...this is *exactly* what you're looking for through... :-/
I know, it's a damn shame...
> Just how platform-independent do you have to be? Unix + Win32, or
> the Mac, OS/2, et al systems as well?
Unix (and clones), and Win32, at least. The more the merrier.
> You can try dot locking it. -Creating a $filename.lock file as an
> indicator to the other process that the file is "locked". Remember
> to open the dot lock file in O_EXCL|O_CREAT|O_WRONLY (I think...)
> mode to make sure you don't get a race condition with two processes
> trying to lock at once. See open(2) for details on the flags.
> You can use the flags via perl's sysopen() call and import the flag
> constants from the Fcntl module ("use Fcntl;" get you the O_*
> stuff).
This sounds more promising - but where is the sysopen() call documented?
(Don't shoot me if it's obvious, please) Is it in the POSIX or Fnctl
modules? (in fact, looking through Altavista, perhaps the Fnctl module,
whatever it is, is the answer).
>: 2) Don't say RTFM - I already have, and found nothing.
>
> I can't believe that, although most of it will probably be talking
> about flock() and friends.
You got it - nothing at all about the actual mechanics of what happens in
PERL when 2 processes try to access the same file.
------------------------------
Date: Mon, 8 Jun 1998 19:53:41 +0100
From: "Jeremy Goldberg" <jgoldberg@dial-but-dont-spam.pipex.com>
Subject: Re: Preventing file conflicts
Message-Id: <6lhc1m$hc2$1@soap.news.pipex.net>
>HOW THE FRICK DO YOU EXPECT ME TO HELP YOU WITH THAT CRAPPY ADDRESS
>YOU NIMROD!?????????????????????????????
You could try just posting to the newsgroup - or better yet, don't bother, I
can do without this kind of help.
------------------------------
Date: Mon, 08 Jun 1998 13:15:49 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: RECOMMEND A PERL BOOK/RESOURCES ??
Message-Id: <357C2A55.1741F2D4@houston.Geco-Prakla.slb.com>
Stephan Carydakis wrote:
>
> Hello All,
>
> Sorry, but I have a menial matter compared to some of the stuff i've
> been reading in 'ere.
>
> I have a background in COBOL(yeah, yeah, i've heard most of the jokes!)
> but am very interested in Perl.
>
> My wife bought me "Programming Perl" for Christmas, and I've been trying
> to learn Perl from this book. I realise its a tad beyond me(the "Grade
> Example" is still awesome in my books!) and am wondering if anyone could
> point me in the direction of a good Intermediate book that teaches Perl.
>
I don't know if 'intermediate' is the right word for it. It probably
isn't. I found 'Learning Perl' to be quite beneficial when starting to
learn Perl.
I had little experience with programming languages (two semesters COBOL
in college, and BASIC/GWBASIC/QBASIC in my previous job). 'Learning
Perl' by Randal L. Schwartz was a great starting point.
I had trouble jumping right into "Programming Perl", however. I used
'Learn Perl in 21 days' by David Till (???). There were some things
that weren't quite right in it, but it had more of a 'tutorial' style
lead you by the hand type layout that guided me well.
Once I finished it, I went back to the camel, and it made tons more
sense.
> I have managed to code a couple of CGI scripts, but am too scared to
> "use strict" on them!!(would someone like to have a laugh and look at
> the code for me???)
>
> Are there any resources where one can say submit a script for some kind
> of evaluation?? or hints?? I've contemplated going back to school part
> time but there are no public schools that offer Perl in Melbourne
> Australia.
>
> Would taking a C++ course help make learning Perl easier??
I'm teaching myself C++ right now. I'd say, probably. If you're not
comfortable with the concept of classes, memory management, etc., it
could prove useful.
I'm going to try to get myself enrolled in a class at some point, but
for now ...
>
> Thanks in advance
>
> Stephan Carydakis
> P.S. Hey Mr Wall, Mr Christiansen, can I come live with one of you guys
> :] ?
HTH.
Dave
--
"Security through obscurity is no security at all."
-comp.lang.perl.misc newsgroup posting
----------------------------------------------------------------------
Dave Barnett U.S.: barnett@houston.Geco-Prakla.slb.com
DAPD Software Support Eng U.K.: barnett@gatwick.Geco-Prakla.slb.com
----------------------------------------------------------------------
------------------------------
Date: 8 Jun 1998 17:41:37 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Skipping iterations in while
Message-Id: <6lh7oh$efo$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
olm@mail1.csun.edu writes:
:How can I skip the very first, (or for that matter "any") iteration of a
:while loop.
:
:I am reading in the output of a unix command, the first line of which I
:don't need, and I need to
:ignore somehow. Is there a control statement in perl that would skip a
:particular iteration in the w
:while loop.
my $seen;
while (<FH>) {
next unless $seen++;
}
or even
<FH>; # discard
while (<FH>) {
}
--tom
--
Do not meddle in the affairs of Wizards, for you are crunchy and
go well with milk.
------------------------------
Date: 8 Jun 1998 14:37:25 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Skipping iterations in while
Message-Id: <6lhb15$nr$1@monet.op.net>
Keywords: aristocracy ferris nucleate rail
In article <357C1153.750F836F@mail1.csun.edu>,
Ovanes Manucharyan <olm@mail1.csun.edu> wrote:
>How can I skip the very first, (or for that matter "any") iteration of a
>while loop.
`next'
------------------------------
Date: Mon, 08 Jun 1998 13:33:24 -0500
From: "Vincent M. Probasco" <probavm@cat.com>
Subject: substitution not working
Message-Id: <357C2E74.645428E6@cat.com>
Alright, I know this is an easy one. Forgive me, but I've been looking
at this one for awhile. Yes,
I've checked the manual and the FAQs. Maybe I'm just missing something
but why isn't this
code working ?
$osee = "<See?>";
$sub = "<person><TD>".$form_data{'signy'}."</TD><See?>";
$line =~ s/$osee/$sub/;
Thanks for any help in advance. By the way. If all you're going to do is
complain that this is too easy
of a question then please don't bother posting. :-) Thanks again.
Vince
------------------------------
Date: Mon, 08 Jun 1998 14:30:50 -0500
From: Richard Gunkel <ragunkel@att.com>
Subject: Substr
Message-Id: <357C3BEA.A04711B1@att.com>
I'm trying to use substr to remove JUST the first 4 Characters from a
String read form <STDIN>
The String is a Fixed width Format:
" San Diego 51 test"
" Portland 132 false"
" Troy 12235 te"
The problem is the output is:
San Diego 51 test
Portland 132 false
Troy 12235 te
The code I'm working with is a follows:
$shortline = substr( $line, 4, 100);
print "$shortline \n";
Thanks,
Rich Gunkel
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
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 2813
**************************************