[RndTbl] strange race condition on file entries

Trevor Cordes trevor at tecnopolis.ca
Sun Feb 2 23:05:28 CST 2014


But after programming heavily in Perl for 22 years (!!!) I can safely say I pretty much have the quirks and syntax oddities nailed. This is the first time in a long time something like this one has bit me, and it's understandable because I rarely use the glob op.

If you don't like all the weirdness, the beauty of Perl is you can instead just program it as though it was C without malloc. I like choice.



-------- Original message --------
From: Sean Walberg <sean at ertw.com> 
Date:2014/02/02  20:00  (GMT-06:00) 
To: Continuation of Round Table discussion <roundtable at muug.mb.ca> 
Subject: Re: [RndTbl] strange race condition on file entries 

While I will always manage my life by the three great virtues, I must thank you for reminding me why I gave up slinging Perl. DWIM and all the sigils drive a man to an early grave, or at least a lot of nights debugging.

Sean


On Sun, Feb 2, 2014 at 1:10 PM, Trevor Cordes <trevor at tecnopolis.ca> wrote:
I forgot to post what *does* work.  There are a few different
ways.

You can force the glob to return a list (hence no caching/iterating):

if (!@{[<$prefix-*>]}) {

That's sure ugly, but it makes sense.  [] forces the <> to return list
and turns it into an anon array-ref.  @ then derefs.  {} is required by
the parser to make sense of it all.  !@ then does its normal thing of
meaning "if there are zero elements in this array".

You could also force it to list by assigning to an array:

if (!(@a=<$prefix-*>)) {

But I hate using temp vars when we don't need to; when the results are
throwaway.

Strangely, using the normal "we want a list" syntax of just putting ()
around the expression doesn't work in this case.  I'm not sure why:

if (!(<$prefix-*>)) {  # doesn't work

Also strangely, while perl has a "scalar" function to force a scalar
(non-list) result, it doesn't have a "list" or "array" function to
force a list.  The scalar docs say list isn't necessary as it's usually
the default/implied or can be forced with ().  Woops, looks like I
found a corner case.

Ya, I could have been certain everything worked in the first place by
doing opendir and iterating through the results, like one would in
C, but the whole purpose of using perl is to do as much as possible in
as few characters and lines.  Laziness is the #1 programmer virtue,
according to L.Wall and R.Schwarz.
_______________________________________________
Roundtable mailing list
Roundtable at muug.mb.ca
http://www.muug.mb.ca/mailman/listinfo/roundtable



-- 
Sean Walberg <sean at ertw.com>    http://ertw.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.muug.mb.ca/pipermail/roundtable/attachments/20140202/9cd24759/attachment-0001.html>


More information about the Roundtable mailing list