develooper Front page | perl.fwp | Postings from May 2012

Re: seeking golfing advice

Thread Previous | Thread Next
From:
Peter Makholm
Date:
May 16, 2012 05:03
Subject:
Re: seeking golfing advice
Message ID:
87aa181ggz.fsf@vps1.hacking.dk
damien krotkine <dkrotkine@gmail.com> writes:

> Indeed grep is much better. As the code is used in a more complex
> structured I got lost and confused and ended up using map, blah.
>
> $|-- was what I was looking for :)

No, reading my posts again it I see that it clearly doesn't do what you
ask for. You are actually looking for --$|.

> Finally, one question : why is  $|-- not recommended in production, if
> the following conditions are met : I'm not running in threads, not in
> an event-loop that might be affected by $| being set, and I'll take
> care of resetting $| appropriately at the end.

It depends on an obscure, undocumented feature of a magic variable, which
unless used correct may have an unintended action at a distance. This
makes the code hard to maintain for the next developer (which might be
youself 14 days down the road).

What do you think you are optimizing for?

I would guess that the $| is also a bit slower, as it needs to at least
test if the filehandle needs to be flushed even though you know that no
one had the chance to write to it.

So basically you are trading 8 characters for readability and probably
speed. Why do you want that?

//Makholm



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About