[RndTbl] strange race condition on file entries

Sean Walberg sean at ertw.com
Sun Feb 2 20:00:48 CST 2014


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/ff3ea0c7/attachment.html>


More information about the Roundtable mailing list