bareword

Why do some users quote classnames in Perl?

孤街浪徒 提交于 2019-12-22 03:52:55
问题 Looking at Type::Tiny, I see that the class name in the call to Type::Tiny->new is quoted in the official docs, my $NUM = "Type::Tiny"->new( name => "Number", constraint => sub { looks_like_number($_) }, message => sub { "$_ ain't a number" }, ); Why is this? Is this mere style? Is there any performance ramifications for this practice? 回答1: Take a simpler example package Foo { sub new { die 7 } }; package Bar { sub new { die 42 } }; sub Foo { "Bar" } Foo->new(); In the above example, the

Bare words / new keywords in Python

放肆的年华 提交于 2019-12-20 09:54:05
问题 I wanted to see if it was possible to define new keywords or, as they're called in WAT's Destroy All Software talk when discussing Ruby, bare words, in Python. I came up with an answer that I couldn't find elsewhere, so I decided to share it Q&A style on StackOverflow. 回答1: I've only tried this in the REPL, outside any block, so far. It may be possible to make it work elsewhere, too. I put this in my python startup file: def bareWordHandler(type_, value, traceback_): if isinstance(value,

Why does Perl open() documentation use two different FILEHANDLE styles?

半腔热情 提交于 2019-12-06 23:19:55
问题 The documentation for the open function shows the syntax of open() as: open FILEHANDLE,EXPR open FILEHANDLE,MODE,EXPR open FILEHANDLE,MODE,EXPR,LIST open FILEHANDLE,MODE,REFERENCE open FILEHANDLE Down in the examples they have places where a normal $-prefixed variable is used for the file handle: open(my $fh, "<", "input.txt") and also examples where a bareword is used: open(FOO, "|tr '[a-z]' '[A-Z]'"); One question is what is the name of each style as in "I am using _ _ for a filehandle" in

Why does Perl open() documentation use two different FILEHANDLE styles?

对着背影说爱祢 提交于 2019-12-05 03:36:56
The documentation for the open function shows the syntax of open() as: open FILEHANDLE,EXPR open FILEHANDLE,MODE,EXPR open FILEHANDLE,MODE,EXPR,LIST open FILEHANDLE,MODE,REFERENCE open FILEHANDLE Down in the examples they have places where a normal $-prefixed variable is used for the file handle: open(my $fh, "<", "input.txt") and also examples where a bareword is used: open(FOO, "|tr '[a-z]' '[A-Z]'"); One question is what is the name of each style as in "I am using _ _ for a filehandle" in each case? The other is, why did they start using bare words for open() in the documentation? It

Bare words / new keywords in Python

狂风中的少年 提交于 2019-12-02 20:38:59
I wanted to see if it was possible to define new keywords or, as they're called in WAT's Destroy All Software talk when discussing Ruby, bare words, in Python. I came up with an answer that I couldn't find elsewhere, so I decided to share it Q&A style on StackOverflow. I've only tried this in the REPL, outside any block, so far. It may be possible to make it work elsewhere, too. I put this in my python startup file: def bareWordHandler(type_, value, traceback_): if isinstance(value, SyntaxError): import traceback # You can probably modify this next line so that it'll work within blocks, as