[18894] in Perl-Users-Digest
Perl-Users Digest, Issue: 1062 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 5 14:06:10 2001
Date: Tue, 5 Jun 2001 11:05:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991764318-v10-i1062@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 5 Jun 2001 Volume: 10 Number: 1062
Today's topics:
Re: 2 questions about flock <m.grimshaw@salford.ac.uk>
Re: 2 questions about flock <keesh@users.sf.net>
Re: 2 questions about flock (Anno Siegel)
Re: 2 questions about flock <m.grimshaw@salford.ac.uk>
Re: 2 questions about flock (Steve)
Re: 2 questions about flock (Abigail)
Re: 2 questions about flock <m.grimshaw@salford.ac.uk>
[ANNOUNCE] Apprenticeship Hour at YAPC::NA (Adam Turoff)
ANNOUNCE: AxKit 1.4 <matt@sergeant.org>
ANNOUNCE: DBD::Chart 0.41 is now available <darnold@earthlink.net>
Any Emacs/Perl Gurus <skpurcell@hotmail.com>
Re: Any Emacs/Perl Gurus <thunderbear@bigfoot.com>
Re: Any Emacs/Perl Gurus <zigouras@mail.med.upenn.edu>
Re: Best way to do this? <bcoon@sequenom.com>
Re: Bug in assignment operator <skilchen@swissonline.ch>
Re: Bug in assignment operator (Anno Siegel)
Re: Bug in assignment operator <godzilla@stomp.stomp.tokyo>
Re: Bug in assignment operator <godzilla@stomp.stomp.tokyo>
Re: Bug in assignment operator (Abigail)
Re: Bug in assignment operator nobull@mail.com
Re: Bug in assignment operator ctcgag@hotmail.com
cerificate viewer (Ian)
Re: cerificate viewer <mischief@velma.motion.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 05 Jun 2001 17:28:54 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: 2 questions about flock
Message-Id: <3B1D08C6.38CD1CDA@salford.ac.uk>
Garry Williams wrote:
>
> On Tue, 05 Jun 2001 09:51:52 +0100, Mark Grimshaw
> <m.grimshaw@salford.ac.uk> wrote:
>
> > Any ideas about flock and a db_fle that is tie'd?
>
> Yes. Don't. See the DB_File manual page for why. Use Anno's
> suggestion instead.
>
Final question about flock I hope. I'm locking the db_file by locking
another file alongside it. To test this, I have the following script
which just locks the file and sits in a loop forever until I ^C it at
which point I assume the LOCK_EX is relinquished:
#!/usr/local/bin/perl -w
use Fcntl qw(LOCK_EX);
$lock = 'db/lock';
open(LOCK, ">$lock") || die "$!\n\n";
flock(LOCK, LOCK_EX);
for(;;)
{
}
exit;
In my CGI script, I have the following:
use Fcntl qw(LOCK_EX);
$lock = 'db/lock';
for(;;)
{
last if(open(LOCK, ">$lock"));
}
# continue with script
If I've got the logic correct, the second script sits in the for(;;)
loop until it can open the $lock file which it can only do (assuming I
have all permissions correct which I do) when the LOCK_EX is
relinquished from the first script by ^C'ing it. However, after
termination of the first script, the second continues in its loop. What
am I doing wrong?
------------------------------
Date: Tue, 05 Jun 2001 16:34:48 GMT
From: "Ciaran McCreesh" <keesh@users.sf.net>
Subject: Re: 2 questions about flock
Message-Id: <IS7T6.5635$IY1.979451@news1.cableinet.net>
In article <3B1D08C6.38CD1CDA@salford.ac.uk>, "Mark Grimshaw"
<m.grimshaw@salford.ac.uk> said:
> Final question about flock I hope. I'm locking the db_file by locking
> another file alongside it. To test this, I have the following script
> which just locks the file and sits in a loop forever until I ^C it at
> which point I assume the LOCK_EX is relinquished:
I don't think it does necessarily... You could do something like wait for
an input on STDIN if you want a controlable delay, just my $foo =
<STDIN>; will wait until you hit return.
--
Ciaran McCreesh
mail: keesh at users dot sf dot net
web: http://www.opensourcepan.com
------------------------------
Date: 5 Jun 2001 16:51:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: 2 questions about flock
Message-Id: <9fj2lo$qcf$1@mamenchi.zrz.TU-Berlin.DE>
According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
> Garry Williams wrote:
> >
> > On Tue, 05 Jun 2001 09:51:52 +0100, Mark Grimshaw
> > <m.grimshaw@salford.ac.uk> wrote:
> >
> > > Any ideas about flock and a db_fle that is tie'd?
> >
> > Yes. Don't. See the DB_File manual page for why. Use Anno's
> > suggestion instead.
> >
>
> Final question about flock I hope. I'm locking the db_file by locking
> another file alongside it. To test this, I have the following script
> which just locks the file and sits in a loop forever until I ^C it at
> which point I assume the LOCK_EX is relinquished:
>
>
> #!/usr/local/bin/perl -w
>
> use Fcntl qw(LOCK_EX);
> $lock = 'db/lock';
>
> open(LOCK, ">$lock") || die "$!\n\n";
> flock(LOCK, LOCK_EX);
> for(;;)
> {
>
> }
Better just sleep() for a long time here. sleep() can also be
interrupted by ^C.
> exit;
>
> In my CGI script, I have the following:
>
> use Fcntl qw(LOCK_EX);
> $lock = 'db/lock';
> for(;;)
> {
> last if(open(LOCK, ">$lock"));
> }
>
> # continue with script
>
> If I've got the logic correct, the second script sits in the for(;;)
> loop until it can open the $lock file which it can only do (assuming I
> have all permissions correct which I do) when the LOCK_EX is
> relinquished from the first script by ^C'ing it. However, after
> termination of the first script, the second continues in its loop. What
> am I doing wrong?
You misunderstand the advisory character of file locking. Even an
exclusive lock won't stop another program from opening the file.
It *will* stop it from getting another lock (of any kind) to the
file. So the relevant part of your "CGI script" should be
open LOCK, $lock or die "Can't read $lock\n";
flock LOCK, LOCK_SH or die "Can't lock $lock\n";
print "got shared lock\n";
This will print "got shared lock" as soon as the first script gives
up its lock, but not before.
Anno
------------------------------
Date: Tue, 05 Jun 2001 18:00:51 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: 2 questions about flock
Message-Id: <3B1D1043.15BAC5FF@salford.ac.uk>
Ciaran McCreesh wrote:
>
> In article <3B1D08C6.38CD1CDA@salford.ac.uk>, "Mark Grimshaw"
> <m.grimshaw@salford.ac.uk> said:
> > Final question about flock I hope. I'm locking the db_file by locking
> > another file alongside it. To test this, I have the following script
> > which just locks the file and sits in a loop forever until I ^C it at
> > which point I assume the LOCK_EX is relinquished:
>
> I don't think it does necessarily... You could do something like wait for
> an input on STDIN if you want a controlable delay, just my $foo =
> <STDIN>; will wait until you hit return.
hmm - OK I've modified the lock file script to wait for 20 seconds or
so:
#!/usr/local/bin/perl -w
use Fcntl qw(LOCK_EX LOCK_UN);
$lock = 'db/lock';
$old = time;
open(LOCK, ">$lock") || die "$!\n\n";
flock(LOCK, LOCK_EX);
$new = time;
while(($new - $old) < 20)
{
$new = time;
}
flock(LOCK, LOCK_UN); # just in case close (LOCK) does not actually
unlock it
close LOCK;
exit;
with the same as before in the CGI script:
for(;;)
{
last if(open(LOCK, ">$lock"));
}
I get the same problem - the for(;;) loop sits there forever even when
the locking script has exited.
If I comment out the for(;;) loop and have:
open(LOCK, ">$lock") || die;
while the locking script is NOT running, the script proceeds so there's
nothing (much) wrong with the rest of the code.
------------------------------
Date: 5 Jun 2001 17:08:48 GMT
From: steve@zeropps.uklinux.net (Steve)
Subject: Re: 2 questions about flock
Message-Id: <slrn9hpv00.ler.steve@zero-pps.localdomain>
I also have a question about file locking.
Can I open a file read it's contents and rewrite the
enitre file before soemone else gets to write to it?
Or do I really need to use a database?
Currently the only way that I can think of doing this
involves closing the file after reading (and dropping the
lock), before rewriting the file. Updating won't do as I
need to change some content that may be in the middle of
the file.
--
Cheers
Steve email mailto:steve@zeropps.uklinux.net
%HAV-A-NICEDAY Error not enough coffee 0 pps.
web http://www.zeropps.uklinux.net/
or http://start.at/zero-pps
4:01pm up 123 days, 16:50, 2 users, load average: 1.00, 1.00, 1.00
------------------------------
Date: Tue, 5 Jun 2001 17:09:10 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: 2 questions about flock
Message-Id: <slrn9hq4hm.5c3.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCXXXV
September MCMXCIII in <URL:news:9fi9oh$1ll$1@mamenchi.zrz.TU-Berlin.DE>:
<> [Please, in the future, put your reply _after_ the suitably trimmed text
<> you reply to. It's the commonly accepted quoting style on this
<> newsgroup, and Usenet in general. Thanks]
<>
<> According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
<> > Thanks,
<> >
<> > So presumably, if I LOCK_SH/LOCK_EX a file that already has a LOCK_EX,
<> > the former will wait at that point in the script for the latter to be
<> > LOCK_UN'd?
<>
<> LOCK_UN is rarely used. The standard way of releasing a lock is
<> by closing the filehandle.
<>
<> > Any ideas about flock and a db_fle that is tie'd? Would I have to
<> > open() the db_file for writing, then LOCK_EX it before tieing it?
<>
<> That is a possibility. It is more common to keep an extra lock file
<> besides the database file(s) and lock that.
And that's an excellent example of why you might want to use LOCK_UN.
A long living program that repeatedly accesses a database file, using
an extra lock file to monitor access, might want to open the lock file
once, and lock using LOCK_SH/LOCK_EX and unlock with LOCK_UN, avoiding
the need to repeatedly open the lock file.
Abigail
--
BEGIN {print "Just " }
CHECK {print "another "}
INIT {print "Perl " }
END {print "Hacker\n"}
------------------------------
Date: Tue, 05 Jun 2001 18:09:54 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: 2 questions about flock
Message-Id: <3B1D1262.206266A6@salford.ac.uk>
Anno Siegel wrote:
>
> According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
> > Garry Williams wrote:
> > >
> > > On Tue, 05 Jun 2001 09:51:52 +0100, Mark Grimshaw
> > > <m.grimshaw@salford.ac.uk> wrote:
> > >
> > > > Any ideas about flock and a db_fle that is tie'd?
> > >
> > > Yes. Don't. See the DB_File manual page for why. Use Anno's
> > > suggestion instead.
> > >
> >
> > Final question about flock I hope. I'm locking the db_file by locking
> > another file alongside it. To test this, I have the following script
> > which just locks the file and sits in a loop forever until I ^C it at
> > which point I assume the LOCK_EX is relinquished:
> >
> >
> > #!/usr/local/bin/perl -w
> >
> > use Fcntl qw(LOCK_EX);
> > $lock = 'db/lock';
> >
> > open(LOCK, ">$lock") || die "$!\n\n";
> > flock(LOCK, LOCK_EX);
> > for(;;)
> > {
> >
> > }
>
> Better just sleep() for a long time here. sleep() can also be
> interrupted by ^C.
>
> > exit;
> >
> > In my CGI script, I have the following:
> >
> > use Fcntl qw(LOCK_EX);
> > $lock = 'db/lock';
> > for(;;)
> > {
> > last if(open(LOCK, ">$lock"));
> > }
> >
> > # continue with script
> >
> > If I've got the logic correct, the second script sits in the for(;;)
> > loop until it can open the $lock file which it can only do (assuming I
> > have all permissions correct which I do) when the LOCK_EX is
> > relinquished from the first script by ^C'ing it. However, after
> > termination of the first script, the second continues in its loop. What
> > am I doing wrong?
>
> You misunderstand the advisory character of file locking. Even an
> exclusive lock won't stop another program from opening the file.
In which case why is the for(;;) loop not exited when the file is
open'd?
> It *will* stop it from getting another lock (of any kind) to the
> file. So the relevant part of your "CGI script" should be
>
> open LOCK, $lock or die "Can't read $lock\n";
> flock LOCK, LOCK_SH or die "Can't lock $lock\n";
> print "got shared lock\n";
>
> This will print "got shared lock" as soon as the first script gives
> up its lock, but not before.
I've modifed what you put above in the CGI script with:
for(;;)
{
flock(LOCK, LOCK_SH) or next;
last;
}
It still sits in the loop when the locking script exits.
------------------------------
Date: 5 Jun 2001 10:53:42 -0400
From: ziggy@panix.com (Adam Turoff)
Subject: [ANNOUNCE] Apprenticeship Hour at YAPC::NA
Message-Id: <9firpm$rb6$1@panix2.panix.com>
As some of you may have noticed from the YAPC schedule[1], I'll be hosting
the "Perl Apprenticeship Hour" next week.
I'm looking for brief descriptions of projects that are
looking for some help, including:
* documentation * tools
* tutorials * bugfixes
* modules * enhancements to existing code
* websites * collaborative efforts
* test code * program suites
If you plan to attend YAPC::America next week, and have:
- an idea for a project, but need extra tuits
- an idea for a project that would be a good way to mentor a beginner
- an idea for a project, don't have time to do it, and don't have a
lot of time to explain it
then please send a brief description ASAP to <ziggy@perl.org>.
The apprenticeship hour will be run much like mjd's Lightning Talks,
where presenters will have ~5 minutes next Wednesday to discuss an
idea for a project.
Submissions should be received by Thursday, June 7th. Presenters
for the Apprenticeship Hour will be notified by Friday, June 8th.
Thanks,
Z.
[1] http://www.yapc.org/America/talks.shtml#schedule
------------------------------
Date: Tue, 05 Jun 2001 17:56:36 +0100
From: Matt Sergeant <matt@sergeant.org>
Subject: ANNOUNCE: AxKit 1.4
Message-Id: <thq4be29m7elb6@corp.supernews.com>
AxKit is a module for building web sites using server-side transformations
of XML based content. It contains many features for delivering the same
content to different devices, and also for building dynamic content for
different devices.
AxKit 1.4 is a major milestone in the development of AxKit, with a very
large list of changes. AxKit is being used on a number of commercial sites,
such as AxKit.com, Take23.org, and PDAMD.com.
http://axkit.org/
http://axkit.org/download/AxKit-1.4.tar.gz (and also on CPAN, of course)
Changes since 1.3:
- Config directives no longer implemented by Apache::ExtUtils
- New TaglibHelper module, makes writing XSP taglibs almost trivial.
- Build checks for iconv library - should make things smoother on *BSD
- Known bug in Filter provider is fixed
- Major memory leak cleanup
- Added LibXSLT language module (for use with XML::LibXSLT). This is
over twice as fast as XML::Sablotron, and more compliant.
- Added AxAddURIProcessor config directive
- Added AxLogDeclines config directive (replaces PerlSetVar equivalent)
- Added import_templates() to XPathScript
- XSP now uses SAX to generate code
- Sablot.pm allows you to set the outgoing mime type
- Many fixes to AxKit.xs compiled directives (hopefully making it work
for more people now)
- Removed eval{} stuff around XML parsing in Provider.pm as it seemed to
be causing segfaults in Perl 5.6.1
- Fixes to LibXSLT language module to make it work with new versions of
XML::LibXSLT (and the core libxslt library).
- Cleaned up error handling, and error stylesheets significantly
- Removed Storable from XPathScript (to get control of the segfaults)
- Implemented has_changed() for all "cache" bits
- Improved error handling with an AxStackTrace config directive
allowing the Error Stylesheet to get a full stack trace.
- Doc fixes to stop pod2man complaining.
- AxKit now adds AxKit/Version to your Server string (for netcraft!)
- Switched xml_string to pnotes so you can have binary nulls in the
output (e.g. for PDFs).
- Added some configuration tidbits to INSTALL
- Much better (though not 100% there) test harness code
- Major fixes to Makefile.PL (to work better on *BSD and Win32)
- XML::Parser no longer needed if you have libxml2 installed. This will
allow AxKit to work with Apaches that have expat enabled!
- XSP pages can implement a has_changed() function, which allows you to
control the caching of the results (can have significant performance
increases on dynamic pages)
- Providers responsible for returning declined (this allows for non-file
providers to not end up in a 404 when doing e.g. passthru)
- Added AxNoCache option to turn off caching on purpose.
- split AxKit.xs into more managable files
- Better error messages from CharsetConv (iconv)
- Added a PDF slideshow builder called AxPoint
- Sablot fix for changing content-type.
- Much cleaner handling of character set conversions
- AxKit::Apache->request() added (similar to Apache->request())
- Cache maintains content-type more sanely.
- Many, many minor bug fixes.
--
<Matt/>
/|| ** Founder and CTO ** ** http://axkit.com/ **
//|| ** AxKit.com Ltd ** ** XML Application Serving **
// || ** http://axkit.org ** ** XSLT, XPathScript, XSP **
// \\| // ** mod_perl news and resources: http://take23.org **
\\//
//\\
// \\
------------------------------
Date: Fri, 01 Jun 2001 20:28:49 GMT
From: "Dean Arnold" <darnold@earthlink.net>
Subject: ANNOUNCE: DBD::Chart 0.41 is now available
Message-Id: <thq1ochgd7ls86@corp.supernews.com>
DBD::Chart 0.41 is now available from either
http://home.earthlink.net/~darnold/dbdchart/ or from CPAN (shortly).
Changes from 0.40:
- fix to strip quotes from string literal in INSERT stmt
- fix for literal data index in prepare of INSERT
- fix for Y-axis tick alignment when no grid is requested
FYI: DBD::Chart is a Perl DBI driver abstraction for rendering charts
and graphs using a variant of SQL. Review the DBD::Chart homepage at
http://home.earthlink.net/~darnold/dbdchart/ for detailed
information.
Regards,
Dean Arnold
------------------------------
Date: Tue, 5 Jun 2001 11:48:55 -0500
From: "spurcell" <skpurcell@hotmail.com>
Subject: Any Emacs/Perl Gurus
Message-Id: <3b1d0de1$0$12005@wodc7nh0.news.uu.net>
Hello,
I am using Emacs, and heard that it can color code my code, eg. subroutines,
variables, etc.
My NT install of Emacs is evidently not configured and was wondering how
this is done? I have surged the emacs sites, but it gets rather confusing,
and appears that emacs could be a full time job for some.
Anyway, I want to color code .pl files for my perl and .plex PerlEx files.
Could someone please assist?
Thanks
Scott
------------------------------
Date: Tue, 05 Jun 2001 18:57:38 +0100
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Re: Any Emacs/Perl Gurus
Message-Id: <3B1D1D92.1F05EC8E@bigfoot.com>
spurcell wrote:
>
> Hello,
> I am using Emacs, and heard that it can color code my code, eg. subroutines,
> variables, etc.
> Could someone please assist?
Look in the menu for "Help" -> "Options".
--
Thorbjørn Ravn Andersen "...plus...Tubular Bells!"
http://bigfoot.com/~thunderbear
------------------------------
Date: Tue, 5 Jun 2001 13:30:08 -0400
From: Nico F Zigouras <zigouras@mail.med.upenn.edu>
To: spurcell <skpurcell@hotmail.com>
Subject: Re: Any Emacs/Perl Gurus
Message-Id: <Pine.OSF.4.10.10106051326170.16478-100000@dolphin.upenn.edu>
You need to have global font lock turned on. On my windows
version of emacs I go to Help -> Options -> and check Global Font Lock.
You can set it to always be turned on in your .emacs file with the lines:
(setq font-lock-maximum-decoration t) ; you might hate this
(global-font-lock-mode 1 t);
I would also suggest that you use the CPerl mode instead of the default
Perl mode, put this line in your .emacs to do that:
(autoload 'cperl-mode "cperl-mode"
"alternate mode for editing Perl programs" t)
(setq auto-mode-alist
(append '(("\\.\\([pP][Llm]\\|al\\)$" . cperl-mode)) auto-mode-alist))
That should do it.
On Tue, 5 Jun 2001, spurcell wrote:
>Hello,
>I am using Emacs, and heard that it can color code my code, eg. subroutines,
>variables, etc.
>
>My NT install of Emacs is evidently not configured and was wondering how
>this is done? I have surged the emacs sites, but it gets rather confusing,
>and appears that emacs could be a full time job for some.
>
>Anyway, I want to color code .pl files for my perl and .plex PerlEx files.
>
>Could someone please assist?
>
>Thanks
>Scott
>
>
>
>
------------------------------
Date: Tue, 05 Jun 2001 08:49:32 -0700
From: BCC <bcoon@sequenom.com>
Subject: Re: Best way to do this?
Message-Id: <3B1CFF8C.392C36F1@sequenom.com>
Thanks for the replys, both solutions were very elegant!
Bryan
------------------------------
Date: Tue, 5 Jun 2001 17:48:01 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: Bug in assignment operator
Message-Id: <9fivh8$45hkg$1@ID-13368.news.dfncis.de>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> schrieb im Newsbeitrag
news:9fient$9ji$1@mamenchi.zrz.TU-Berlin.DE...
>
> my $num_parts = () = split /,/, 'a,b,c';
>
> sets $num_parts to 1, not 3. I observed this with v5.6.0 and v5.6.1.
>
You missed the following part from perldoc -f split:
When assigning to a list, if LIMIT is omitted, Perl
supplies a LIMIT one larger than the number of variables
in the list, to avoid unnecessary work
You assign to a list of 0 elements, so Perl assumes a LIMIT of 1 and
that is exactly what you get in $num_parts.
------------------------------
Date: 5 Jun 2001 16:17:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bug in assignment operator
Message-Id: <9fj0mv$ou3$1@mamenchi.zrz.TU-Berlin.DE>
According to Samuel Kilchenmann <skilchen@swissonline.ch>:
>
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> schrieb im Newsbeitrag
> news:9fient$9ji$1@mamenchi.zrz.TU-Berlin.DE...
> >
> > my $num_parts = () = split /,/, 'a,b,c';
> >
> > sets $num_parts to 1, not 3. I observed this with v5.6.0 and v5.6.1.
> >
> You missed the following part from perldoc -f split:
>
> When assigning to a list, if LIMIT is omitted, Perl
> supplies a LIMIT one larger than the number of variables
> in the list, to avoid unnecessary work
>
> You assign to a list of 0 elements, so Perl assumes a LIMIT of 1 and
> that is exactly what you get in $num_parts.
Aha! You are absolutely right, I overlooked that part. Thanks for
pointing it out. So the simple solution, if really needed, is
my $num_parts = () = split /,/, 'a,b,c', -1;
Anno
------------------------------
Date: Tue, 05 Jun 2001 09:33:01 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Bug in assignment operator
Message-Id: <3B1D09BD.506CD08F@stomp.stomp.tokyo>
Samuel Kilchenmann wrote:
> Anno Siegel wrote:
> > my $num_parts = () = split /,/, 'a,b,c';
> > sets $num_parts to 1, not 3. I observed this with v5.6.0 and v5.6.1.
> You missed the following part from perldoc -f split:
> When assigning to a list, if LIMIT is omitted, Perl
> supplies a LIMIT one larger than the number of variables
> in the list, to avoid unnecessary work
> You assign to a list of 0 elements, so Perl assumes a LIMIT of 1 and
> that is exactly what you get in $num_parts.
Yes and no. There is an inherent syntax problem as well
using his code snippet.
At first glance I would be tempted to say his code
snippet, as a whole, is evaluated only once, thus
returning a value of one, regardless of the split
evaluating multiple times. However, other tests of
his syntax creates a new problem which causes me
to question if his snippet is forcing a singular
evaluation or simply "confusing" perl core with
bad syntax but not fatal syntax.
Either way, his syntax is not a logical conclusion
drawn from the definition of list assignment as
he posted.
Randal, what is truly happening?
Godzilla!
--
#!perl
$input = "a, b, c";
$scalar = ($input);
print "Return: $scalar\n\n";
$input = "a, b, c";
$scalar = ($input) = split /,/, $input;
print "Return: $scalar\n\n";
$input = "a, b, c";
$scalar = ($input = split /,/, $input);
print "Return: $scalar\n\n";
$input = "a, b, c";
$scalar = $input = split /,/, $input;
print "Return: $scalar\n\n";
exit;
PRINTED RESULTS:
________________
Return: a, b, c
Return: 2
Return: 3
Return: 3
------------------------------
Date: Tue, 05 Jun 2001 09:44:03 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Bug in assignment operator
Message-Id: <3B1D0C53.DFB5322A@stomp.stomp.tokyo>
Anno Siegel wrote:
> Samuel Kilchenmann wrote:
> > Anno Siegel wrote:
> > > my $num_parts = () = split /,/, 'a,b,c';
> > > sets $num_parts to 1, not 3. I observed this with v5.6.0 and v5.6.1.
> > You missed the following part from perldoc -f split:
> > When assigning to a list, if LIMIT is omitted, Perl
> > supplies a LIMIT one larger than the number of variables
> > in the list, to avoid unnecessary work
> > You assign to a list of 0 elements, so Perl assumes a LIMIT of 1 and
> > that is exactly what you get in $num_parts.
> Aha! You are absolutely right, I overlooked that part. Thanks for
> pointing it out. So the simple solution, if really needed, is
> my $num_parts = () = split /,/, 'a,b,c', -1;
Your logic is still impaired. You are not providing a valid
solution. You are simply causing the split to be fully
evaluated before providing a return value. Use of a
negative one is not a valid solution; it is bad syntax
producing correct results by coincidence.
It is prudent to test both code and concepts before
announcing a "rule" regarding exhibited behavior
of Perl code.
Godzilla!
--
#!perl
$scalar = () = split /,/, 'a,b,c', -2;
print "Return: $scalar\n\n";
$scalar = () = split /,/, 'a,b,c', -1;
print "Return: $scalar\n\n";
$scalar = () = split /,/, 'a,b,c', 0;
print "Return: $scalar\n\n";
$scalar = () = split /,/, 'a,b,c', 1;
print "Return: $scalar\n\n";
$scalar = () = split /,/, 'a,b,c', 2;
print "Return: $scalar\n\n";
$scalar = () = split /,/, 'a,b,c', 3;
print "Return: $scalar\n\n";
$scalar = () = split /,/, 'a,b,c', 4;
print "Return: $scalar\n\n";
exit;
PRINTED RESULTS:
________________
Return: 3
Return: 3
Return: 1
Return: 1
Return: 2
Return: 3
Return: 3
------------------------------
Date: Tue, 5 Jun 2001 17:13:30 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Bug in assignment operator
Message-Id: <slrn9hq4pq.5c3.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCXXXV
September MCMXCIII in <URL:news:9fient$9ji$1@mamenchi.zrz.TU-Berlin.DE>:
%% "...a list assignment is scalar context returns the number of elements
%% produced by the expression on the right hand side of the assignment"
%% (perlop).
%%
%% This leads to the idiomatic
%%
%% my $num_elements = () = <something to be evaluated in list context>
%%
%% to find how many elements the right hand side produces without keeping
%% them.
%%
%% It doesn't work this way when the expression on the right hand side
%% is a split operation. Specifically,
%%
%% my $num_parts = () = split /,/, 'a,b,c';
%%
%% sets $num_parts to 1, not 3. I observed this with v5.6.0 and v5.6.1.
%%
%% Any comments before I send a bug report?
RTFM.
This behaviour is documented in perlfunc:
When assigning to a list, if LIMIT is omitted,
Perl supplies a LIMIT one larger than the number
of variables in the list, to avoid unnecessary
work.
Hence your result of 1. Use -1 as a third argument.
Abigail
--
$" = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%_ = (Just => another => Perl => Hacker); &{%_};
------------------------------
Date: 05 Jun 2001 18:06:12 +0100
From: nobull@mail.com
Subject: Re: Bug in assignment operator
Message-Id: <u97kyq26wr.fsf@wcl-l.bham.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> my $num_parts = () = split /,/, 'a,b,c';
>
> sets $num_parts to 1, not 3. I observed this with v5.6.0 and v5.6.1.
>
> Any comments before I send a bug report?
This behaviour is as documented in "perldoc -f split":
When assigning to a list, if LIMIT is omitted,
Perl supplies a LIMIT one larger than the number
of variables in the list, to avoid unnecessary
work.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 05 Jun 2001 17:57:10 GMT
From: ctcgag@hotmail.com
Subject: Re: Bug in assignment operator
Message-Id: <20010605135710.740$1I@newsreader.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> my $num_parts = () = split /,/, 'a,b,c';
>
> sets $num_parts to 1, not 3. I observed this with v5.6.0 and v5.6.1.
$num_parts = () = split /,/, 'a,b,c' , -1 ;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet for the Web
------------------------------
Date: 5 Jun 2001 09:33:34 -0700
From: kerrzer@hotmail.com (Ian)
Subject: cerificate viewer
Message-Id: <8b46dba4.0106050833.605da74f@posting.google.com>
How can I decode a base64 encoded x509 certificate so I can get the
information out of it (issuer, valid dates, etc)? Is there a module?
Thanks
------------------------------
Date: Tue, 05 Jun 2001 17:42:06 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: cerificate viewer
Message-Id: <thq6fe8fklmq8a@corp.supernews.com>
In comp.lang.perl.modules Ian <kerrzer@hotmail.com> wrote:
> How can I decode a base64 encoded x509 certificate so I can get the
> information out of it (issuer, valid dates, etc)? Is there a module?
http://search.cpan.org/search?mode=module&query=base64
Chris
--
Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.
------------------------------
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.
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 1062
***************************************