[31810] in Perl-Users-Digest
Perl-Users Digest, Issue: 3073 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 12 21:09:28 2010
Date: Thu, 12 Aug 2010 18:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 12 Aug 2010 Volume: 11 Number: 3073
Today's topics:
"Bizarre copy of HASH in sassign..." bug <no.email@please.post>
Re: "Bizarre copy of HASH in sassign..." bug <nospam-abuse@ilyaz.org>
Re: "Bizarre copy of HASH in sassign..." bug <ben@morrow.me.uk>
Re: "Bizarre copy of HASH in sassign..." bug <no.email@please.post>
Re: FAQ 5.23 I still don't get locking. I just want to <tzz@lifelogs.com>
Re: FAQ 5.23 I still don't get locking. I just want to (Alan Curry)
Re: FAQ 5.23 I still don't get locking. I just want to (David Canzi)
Re: FAQ 5.23 I still don't get locking. I just want to (David Canzi)
Re: FAQ 8.44 How do I tell the difference between error <hjp-usenet2@hjp.at>
Re: sysopen failures <hjp-usenet2@hjp.at>
Re: sysopen failures <derykus@gmail.com>
Re: sysopen failures <hjp-usenet2@hjp.at>
Re: sysopen failures <derykus@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Aug 2010 21:59:25 +0000 (UTC)
From: kj <no.email@please.post>
Subject: "Bizarre copy of HASH in sassign..." bug
Message-Id: <i3v6fs$s0j$1@reader1.panix.com>
Everyone once in a while, my code produces an error message that
looks like this:
Bizarre copy of HASH in sassign at /usr/share/perl/5.10/Carp/Heavy.pm line 96
I think it's an internal bug somewhere, and I can usually find a
way around it, but still, it's puzzling.
The latest manifestation of this problem occurred while I was
writing unit tests for a module. My test script uses Test::More::throws_ok
to check some error conditions. When checking this one error
condition, it generates the message copied above. But if instead
of writing my test like this:
throws_ok { should_fail() } qr/something went awry/, "exception raised";
I write it like this:
eval { should_fail() };
ok $@ =~ qr/something went awry/, "exception raised";
everything's fine: the test passes, and the "Bizarre copy of HASH..."
error disappears.
If anyone can shed some light on this problem, I'd appreciate it.
TIA!
~K
------------------------------
Date: Wed, 11 Aug 2010 22:05:38 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: "Bizarre copy of HASH in sassign..." bug
Message-Id: <slrni667li.uj8.nospam-abuse@powdermilk.math.berkeley.edu>
On 2010-08-11, kj <no.email@please.post> wrote:
> Bizarre copy of HASH in sassign at /usr/share/perl/5.10/Carp/Heavy.pm line 96
> eval { should_fail() };
> ok $@ =~ qr/something went awry/, "exception raised";
>
> everything's fine: the test passes, and the "Bizarre copy of HASH..."
> error disappears.
>
> If anyone can shed some light on this problem, I'd appreciate it.
IIRC, this appears only when one inspects Perl stack, right? Well,
Perl stack is not refcounted, so anything may the there. There is no
guarantie that it contains valid values...
Yours,
Ilya
------------------------------
Date: Thu, 12 Aug 2010 01:39:14 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: "Bizarre copy of HASH in sassign..." bug
Message-Id: <iesbj7-q28.ln1@osiris.mauzo.dyndns.org>
Quoth kj <no.email@please.post>:
>
> Everyone once in a while, my code produces an error message that
> looks like this:
>
> Bizarre copy of HASH in sassign at /usr/share/perl/5.10/Carp/Heavy.pm line 96
>
> I think it's an internal bug somewhere, and I can usually find a
> way around it, but still, it's puzzling.
Yes, it's a bug in Perl. As Ilya said, it's usually related to the fact
the Perl stack isn't refcounted (which is a bug, but not one it appears
to be possible to fix without breaking every XS extension in the world).
Some instances of it get squashed from time to time, so upgrading your
perl may be a solution. Other than that, I'm afraid you just have to
live with workarounds.
> The latest manifestation of this problem occurred while I was
> writing unit tests for a module. My test script uses Test::More::throws_ok
> to check some error conditions. When checking this one error
> condition, it generates the message copied above. But if instead
> of writing my test like this:
>
> throws_ok { should_fail() } qr/something went awry/, "exception raised";
ITYM Test::Exception? T::E uses Sub::Uplevel, which does some slightly
scary things that are more than usually likely to trigger this. Carp is
another common candidate, because they both try to examine the call
stack in ways that tend to provoke bugs.
Ben
------------------------------
Date: Thu, 12 Aug 2010 17:10:21 +0000 (UTC)
From: kj <no.email@please.post>
Subject: Re: "Bizarre copy of HASH in sassign..." bug
Message-Id: <i419tt$4c8$1@reader1.panix.com>
Ben, Ilya: Thanks for confirming my understanding of the situation,
and for the additional info on it.
In <iesbj7-q28.ln1@osiris.mauzo.dyndns.org> Ben Morrow <ben@morrow.me.uk> writes:
>Quoth kj <no.email@please.post>:
>> The latest manifestation of this problem occurred while I was
>> writing unit tests for a module. My test script uses Test::More::throws_ok
>> to check some error conditions....
>ITYM Test::Exception?
Yes, that's what I meant. Thanks for the correction.
~K
------------------------------
Date: Thu, 12 Aug 2010 15:54:15 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: FAQ 5.23 I still don't get locking. I just want to increment the number in the file. How can I do this?
Message-Id: <87eie3imbs.fsf@lifelogs.com>
On Thu, 12 Aug 2010 19:42:13 +0000 (UTC) dmcanzi@remulak.uwaterloo.ca (David Canzi) wrote:
DC> Advice and example code in the FAQs should be useful to typical
DC> perl users, who run the version of perl that came with their
DC> operating system. A quick scan of about 100 machines in my work
DC> environment didn't find any running perl 5.10.
I disagree. The FAQ should target the latest Perl.
Ted
------------------------------
Date: Thu, 12 Aug 2010 22:06:47 +0000 (UTC)
From: pacman@kosh.dhis.org (Alan Curry)
Subject: Re: FAQ 5.23 I still don't get locking. I just want to increment the number in the file. How can I do this?
Message-Id: <i41r9m$vm0$1@speranza.aioe.org>
In article <DZj8o.2656$yr6.1340@newsfe05.iad>,
PerlFAQ Server <brian@theperlreview.com> wrote:
>This is an excerpt from the latest version perlfaq5.pod, which
>comes with the standard Perl distribution. These postings aim to
>reduce the number of repeated questions as well as allow the community
>to review and update the answers. The latest version of the complete
>perlfaq is at http://faq.perl.org .
>
>--------------------------------------------------------------------
>
>5.23: I still don't get locking. I just want to increment the number in
>the file. How can I do this?
>
> Didn't anyone ever tell you web-page hit counters were useless? They
Code problems aside, are hit counters still popular enough for this joke
to work? Do new perl programmers now even know what it refers to? You
know, those people who when they say "RedHat 4", aren't referring to the
one that came with libc5, and who think "Seinfeld" comes from
approximately the same time period as "I Love Lucy"...
--
Alan Curry
------------------------------
Date: Thu, 12 Aug 2010 22:29:53 +0000 (UTC)
From: dmcanzi@remulak.uwaterloo.ca (David Canzi)
Subject: Re: FAQ 5.23 I still don't get locking. I just want to increment the number in the file. How can I do this?
Message-Id: <i41sl1$9q9$1@rumours.uwaterloo.ca>
In article <87eie3imbs.fsf@lifelogs.com>,
Ted Zlatanov <tzz@lifelogs.com> wrote:
>On Thu, 12 Aug 2010 19:42:13 +0000 (UTC) dmcanzi@remulak.uwaterloo.ca
>(David Canzi) wrote:
>
>DC> Advice and example code in the FAQs should be useful to typical
>DC> perl users, who run the version of perl that came with their
>DC> operating system. A quick scan of about 100 machines in my work
>DC> environment didn't find any running perl 5.10.
>
>I disagree. The FAQ should target the latest Perl.
Why?
--
David Canzi | "If the human mind were simple enough for us to understand,
| we would be too simple-minded to understand it." -- anonymous
------------------------------
Date: Thu, 12 Aug 2010 19:42:13 +0000 (UTC)
From: dmcanzi@remulak.uwaterloo.ca (David Canzi)
Subject: Re: FAQ 5.23 I still don't get locking. I just want to increment the number in the file. How can I do this?
Message-Id: <i41iql$rrf$1@rumours.uwaterloo.ca>
In article <8bbaj7-89u1.ln1@osiris.mauzo.dyndns.org>,
Ben Morrow <ben@morrow.me.uk> wrote:
>
>Quoth Justin C <justin.1007@purestblue.com>:
>> On 2010-08-10, PerlFAQ Server <brian@theperlreview.com> wrote:
>>
>> The code example in the original is over 80 columns wide and could be
>> easier to follow - especially in ye olde slrn in an 80 column terminal.
>
>Ooh, yes, that's nasty. I rather suspect someone's gone trawling through
>the docs adding 'or die' everywhere without thinking too hard about the
>formatting.
>
>> I've reformatted it, perhaps $FAQ_maintainer may consider the change?
>>
>> > Anyway, this is what you can do if you can't help yourself.
>> >
>> > use Fcntl qw(:DEFAULT :flock);
>> > sysopen my $fh, "numfile", O_RDWR|O_CREAT
>> > or die "can't open numfile: $!";
>> > flock $fh, LOCK_EX
>> > or die "can't flock numfile: $!";
>> > my $num = <$fh> || 0;
>> > seek $fh, 0, 0
>> > or die "can't rewind numfile: $!";
>> > truncate $fh, 0
>> > or die "can't truncate numfile: $!";
>> > (print $fh $num+1, "\n")
>> > or die "can't write numfile: $!";
>> > close $fh
>> > or die "can't close numfile: $!";
>
>Since autodie has been core since 5.10, this would seem like a perfect
>place to use it. I don't know what the FAQ's policy is on things like
>that (myself, I'm starting to seriously consider adding 'autodie' to
>'warnings' and 'strict' as something I always have on).
Advice and example code in the FAQs should be useful to typical
perl users, who run the version of perl that came with their
operating system. A quick scan of about 100 machines in my work
environment didn't find any running perl 5.10.
--
David Canzi | "If the human mind were simple enough for us to understand,
| we would be too simple-minded to understand it." -- anonymous
------------------------------
Date: Thu, 12 Aug 2010 21:59:50 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 8.44 How do I tell the difference between errors from the shell and perl?
Message-Id: <slrni68klo.8n9.hjp-usenet2@hrunkner.hjp.at>
On 2010-08-10 13:10, brian d foy <brian.d.foy@gmail.com> wrote:
> In article <slrni59df1.v04.hjp-usenet2@hrunkner.hjp.at>, Peter J.
> Holzer <hjp-usenet2@hjp.at> wrote:
>> On 2010-07-31 22:00, PerlFAQ Server <brian@theperlreview.com> wrote:
>> > 8.44: How do I tell the difference between errors from the shell and perl?
>> >
>> > (answer contributed by brian d foy)
>> >
>> > When you run a Perl script, something else is running the script for
>> > you, and that something else may output error messages. The script might
>> > emit its own warnings and error messages. Most of the time you cannot
>> > tell who said what.
>>
>> I find this paragraph confusing. The "something else" that "is running
>> the script for" me is the perl interpreter. But from the rest of this
>> entry I guess that "something else" means the shell, which doesn't run
>> the script, it merely starts it.
>
> Starting it is the same as running it, when most people consider
> "running" to be typing at the command line and hitting enter to kick
> something off.
The target audience of this FAQ is not "most people", but Perl
programmers. More specifically, this question is about possible
confusion caused by two interpreters (the shell and the perl
interpreter) and I don't think it is helpful to add to the confusion by
using vague and misleading language.
Maybe something like:
When you run a Perl script, you often start it from a shell. The
script is compiled and executed by the perl interpreter. Both the
shell and the perl interpreter may output error messages. The script
might emit its own warnings and error messages. Most of the time you
cannot tell who said what.
But I'm not happy with that either, because it covers the normal
situation and not the specific error that the perl script is interpreted
by shell instead of the perl interpreter.
> It sounds like you've sussed it out just fine by reading the whole
> thing. :)
I'm a sysadmin. It's my job to understand users.
hp
------------------------------
Date: Thu, 12 Aug 2010 17:04:57 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: sysopen failures
Message-Id: <slrni683cq.4uu.hjp-usenet2@hrunkner.hjp.at>
On 2010-08-10 22:16, Martijn Lievaart <m@rtij.nl.invlalid> wrote:
> On Tue, 10 Aug 2010 00:20:34 -0700, Marc Girod wrote:
>> On Aug 9, 6:32 pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>>> Stupid suggestion and does not match exactly what you wrote above, but:
>>> Are there maybe two instances of your program running and interfering
>>> with each other?
>>
>> Thanks... This script is invoked via a ~/.forward file, i.e. for every
>> incoming mail. I guess it is very possible that the same mail is
>> presented twice, e.g. if it contains the address twice (?) Again
>> something I should log.
>> But each instance generates its own filenames, and sure, the first would
>> easily clash (protected only by timestamp), but it should impact only
>> the first of the two instances...
>
> In that case I suggest you make sure the filenames are really unique
> (hint, use the pid, available in $$),
Since the files are not removed before the program exits, using the pid
doesn't make the filenames unique. Even with a timestamp with a
resolution of one second there is a chance that the pid wraps around too
fast (although it's pretty unlikely).
> or implement some sort of locking
> mechanism.
O_EXCL is "some kind of locking mechanism": Any already existing file is
"locked" and won't be overwritten. It doesn't wait (wouldn't be very
useful since files aren't deleted) but fails immediately. Then the
program tries a new file name. This looks ok (it is also a usual method
for creating temporary files). Maybe the "try next file filename" part
doesn't work correctly - we haven't seen the code and it probably isn't
well tested.
Oh, and for everything running from a .forward file: Be sure to use the
correct exit codes from sys_exit.h.
hp
------------------------------
Date: Thu, 12 Aug 2010 12:01:18 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: sysopen failures
Message-Id: <8dc41947-90f1-4a88-a1f7-1639ec598e9e@u31g2000pru.googlegroups.com>
On Aug 12, 8:04=A0am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2010-08-10 22:16, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
>
>
>
> > On Tue, 10 Aug 2010 00:20:34 -0700, Marc Girod wrote:
> >> On Aug 9, 6:32=A0pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
...
> > or implement some sort of locking
> > mechanism.
>
> O_EXCL is "some kind of locking mechanism": Any already existing file is
> "locked" and won't be overwritten. It doesn't wait (wouldn't be very
> useful since files aren't deleted) but fails immediately. Then the
> program tries a new file name. This looks ok (it is also a usual method
> for creating temporary files). Maybe the "try next file filename" part
> doesn't work correctly - we haven't seen the code and it probably isn't
> well tested.
It's not clear to me what O_EXCL will do though
since the files are remote and the OP's doc say:
"O_EXCL" may not work on network filesystems ...
This makes me wonder if "not work" might well
manifest as a flurry of false positives for
an error at times but work normally at other
times.
I don't know if there are other network locking
mechanisms that'd be easy or reliable though.
--
Charles DeRykus
------------------------------
Date: Thu, 12 Aug 2010 22:03:43 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: sysopen failures
Message-Id: <slrni68ksv.8n9.hjp-usenet2@hrunkner.hjp.at>
On 2010-08-12 19:01, C.DeRykus <derykus@gmail.com> wrote:
> It's not clear to me what O_EXCL will do though
> since the files are remote and the OP's doc say:
>
> "O_EXCL" may not work on network filesystems ...
>
> This makes me wonder if "not work" might well
> manifest as a flurry of false positives for
> an error at times but work normally at other
> times.
I already covered this in my first posting in this thread. If you can
add anything substantial to that, please do.
hp
------------------------------
Date: Thu, 12 Aug 2010 15:31:49 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: sysopen failures
Message-Id: <02884f9f-4127-40d7-8474-6a40b35b08e0@a4g2000prm.googlegroups.com>
On Aug 12, 1:03=A0pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2010-08-12 19:01, C.DeRykus <dery...@gmail.com> wrote:
>
> > It's not clear to me what O_EXCL will do though
> > since the files are remote and the OP's doc say:
>
> > =A0 =A0"O_EXCL" may not work on network filesystems ...
>
> > This makes me wonder if "not work" might well
> > manifest =A0as a flurry of false positives for
> > an error at times but work normally at other
> > times.
>
> I already covered this in my first posting in this thread. If you can
> add anything substantial to that, please do.
>
I must've missed it. I did see the remark that
'it's very likely that =93File exists=94 is set by
sysopen' without explicit mention of sysopen not
being guaranteed to work over the network.
--
Charles DeRykus
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3073
***************************************