English 中文(简体)
qw(:每ing)在每桶使用线上做了什么?
原标题:What does the qw(:everything) do on a use line in perl?

这是一个令人难堪的问题,但为什么这一条线工作,而另一条则没有作用?

Working line:

use strict;
use warning;
use Wx qw(:everything);
my $dialog = Wx::MessageDialog->new(
    $self,
   "About test
" .  "Version 0.01
",
   "About Test",
   wxOK | wxCENTRE
);

非工作线:

use strict;
use warning;
use Wx;
my $dialog = Wx::MessageDialog->new(
   $self,
   "About test
" .  "Version 0.01
",
   "About Test",
   wxOK | wxCENTRE
);

3. 非工作线的错误信息:

Bareword "wxOK" not allowed while "strict subs" in use at test.pl line 123.
Bareword "wxCENTRE" not allowed while "strict subs" in use at test.pl line 123.
BEGIN not safe after errors--compilation aborted at test.pl line 348.
最佳回答

It is the equivalent of this:

BEGIN {
    require  Wx ;
    Wx->import(  :everything  );
};

该守则将把Wx输入现名空间。 我的猜测是,Wx使用出口商,并且有一批东西可以进口,而需要的是:不间断。

You can check the Wx s source and Exporter s source to try to make more sense of it.

I missed your working/non-working example. The non-working one doesn t work because the wxOK and wxCENTRE constants are not imported into the current namespace. This is done using Exporter, as explained above.

问题回答
qw(:everything)

非常相似

(split    ,  :everything )

So

use Wx qw(:everything);

这与

use Wx  :everything ;

载体:everything <>/code>通过到Wx的例行出口(import)。 斜体完全服从单元,但我假定Wx是“出口我可能出口的一切”。 大多数模块都使用<代码>:所有,如果它们完全提供的话。

除非你提出要求,否则,它就认为Wx don 出口任何东西,例如wxOKwxCENTRE,除非你告诉你,否则在您的名下没有出口。 出口

use Wx qw( wxOK wxCENTRE );

or

use Wx qw( :everything );

在今后的参考中,请包括错误信息,而不要简单地说有些事。





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签