5 ms·
Perl definitely has a lot of non-patterned arcana. For instance, $| This variable, if nonzero, will flush the output buffer after every write() or print() func
by earthboundkid 6y ago
Perl definitely has a lot of non-patterned arcana. For instance,
$| This variable, if nonzero, will flush the output buffer after every write() or print() function. Normally, it is set to 0.
In other languages, you do something like os.stdout.buffered(true) or sys.stdout = io::buffer(sys.stdout) or something like that where you're combining composable pieces: the standard std variable, a standard way of opening files with or without a buffer, etc. Perl instead has an obscure global variable that you have to look up/memorize, and it doesn't even have a sensible name like $STDOUT_BUFFERING, so readers who come across $| in a file have to look it up/recall from rote memorization, or hope it has a good comment above it.
- rlpb 6y agoI'm no fan of Perl, but you can use $OUTPUT_AUTOFLUSH instead if you "use English;". So this isn't really a Perl language thing; it's a style thing. Other languages can be made to look really bad with poor style. The question then becomes what is culturally accepted, and what is not.
- ljm 6y ago`use English;` as a directive feels like the programming equivalent of someone on TV saying "ye ye ye can you say that in English!?" Only, it's the programmer saying it this time, not the layman. Perl is a 10x engineer.
- jschwartzi 6y agoThe problem is that nobody ever tells you these things, the documentation doesn’t cover them and as a result everyone still uses the terrible original syntax.
- gbacon 6y agoWhat do you mean the documentation doesn’t cover them? https://perldoc.perl.org/perlvar.html#SPECIAL-VARIABLES https://perldoc.perl.org/perlvar.html#SPECIAL-VARIABLES
- mfontani 6y agoOne can also: use IO::Handle; STDOUT->autoflush(1); STDERR->autoflush(1);
- justinator 6y agoTMTOWTDI!
- laumars 6y agoTIMTOWTDIBSCINABTE (for those unfamiliar: https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to...)
- daotoad 6y agoTIMTOWTDIBSCINABTE (pronounced "tim toady bicarbonate"). "There’s more than one way to do it, but sometimes consistency is not a bad thing either."
- joosters 6y agoSure, it's got lots of historical baggage, but there are more sensible alternatives to $| - like STDOUT->autoflush(1) - it's not like you have to use the obscure versions of every feature.
- DonHopkins 6y agoThat certainly doesn't solve the problem of other people showboating their knowledge of obscure Perl sigils by using those ridiculous line-noise abbreviations in code you're trying to use and understand, so you have to look up each bit of obscure punctuation in its particular context in order to understand the code. If hard-to-read-and-remember syntax exists, people WILL use it. And some people will make a POINT to use it, because it makes them feel cool. Having two totally but pointlessly different syntaxes for the same thing doesn't absolve you from having to learn both syntaxes, because you'll still encounter other people's code that uses both of them -- it just gives you twice as much syntax to learn. If there's a "sensible alternative", then why does there have to be a "senseless alternative" in the first place?
- joosters 6y agoBecause perl improved over time, but they didn't want to break people's existing code needlessly. No-one ever deliberately invents 'senseless' things, we just discover better ways over time. Sure, if we could somehow magically always invent the best way first of all, that would be great. But we can't, so we make the best of what we have, and improve when we can. But there's no need to punish the existing users of older, 'worse' things.
- DonHopkins 6y agoThe concept of giving functions names spelled out with letters that form words that describe their meaning was invented a long time before Perl figured out that doing that was better than overloading a limited set of ASCII punctuation with random abstract unrelated concepts.
- 6y ago
- wbl 6y ago$| is related to pipes. Much of the sigils are like this.
- proverbialbunny 6y agoIt suddenly makes sense and isn't so bad. The $ is a sigil, so it appears before variables like $var, so it's just saying | it out. When typed at the beginning of a one liner it becomes quite obvious what you want. This is clearly not a feature for a large project, but a quick UNIX style one off awk-like script.
- cutler 6y agoIn Perl `$` is strictly a scalar variable though this can be a reference to an array, hash or object as they are stored as references. Not to be confused with `$` in PHP which simply denotes a variable of any kind. In Bash `$` denotes the value of a variable.