我刚刚向PDL::IO::Touchstone发行版添加了一个新文件,并注意到 CPAN 的索引器显示版本为 undef,因为$VERSION缺少:
module : PDL::IO::MDIF
version: undef
in file: PDL-IO-Touchstone-1.009/lib/PDL/IO/MDIF.pm
status : indexed
Run Code Online (Sandbox Code Playgroud)
所以 ::MDIF 没有$VERSION,但实际上它与 Makefile.PL 中注明的发行版相同:
module : PDL::IO::MDIF
version: undef
in file: PDL-IO-Touchstone-1.009/lib/PDL/IO/MDIF.pm
status : indexed
Run Code Online (Sandbox Code Playgroud)
问题:
$VERSION分开维护?
$VERSIONVERSION_FROMMakefile.PL$VERSION = $PDL::IO::Touchstone::VERSION,但不确定 CPAN 是否会解决这个问题。会吗?我环顾四周,发现了很多关于版本控制实践的讨论,但没有任何关于同一 Perl 发行包中模块版本的讨论。请分享这里的最佳实践应该是什么,我是 Perl 模块的新手,这是我推出的第一个 2 文件发行版。
我确信在发布新的 dist 时我会更新主文件,但不确定当 dist 中其他模块发生更改时我是否会记得更改它们的版本。如果这里有一个低维护选项,那就太好了。
我尝试了下面一些答案中的建议。这些都不起作用:
$VERSION = do { use PDL::IO::Touchstone; $PDL::IO::Touchstone::VERSION };
use PDL::IO::Touchstone; our $VERSION = $PDL::IO::Touchstone::VERSION; …
perlpod文档说可以,L<link to something>但它没有指出引用 Perl 核心函数的正确方法(或者如果确实如此,对我来说并不明显)。
具体来说,我想链接到 所显示的内容perldoc -f wantarray。链接到它的正确方法是什么,以便当您单击 MetaCPAN 和其他遵循链接的 POD 查看器中的链接时,L<...>它会将您带到文档?wantarray
(请注意,这wantarray只是一个内置的 Perl 函数,例如printor open。)
我正在尝试使用Device::SerialPort而不使用裸字 glob,请参阅底部的问题。
这是他们的例子:
$PortObj = tie (*FH, 'Device::SerialPort', $Configuration_File_Name)
print FH "text";
Run Code Online (Sandbox Code Playgroud)
...但是用 *FH 污染命名空间感觉很脏...
我tie(my $fh, ...)像你一样尝试过open (my $fh, ...),但Device::SerialPort没有实现TIESCALAR,所以它给出了一个错误。
这是我的肮脏黑客,但它仍然使用裸字,我什至无法让它限制裸字 glob 的范围:
# This does _not_ scope *FH, but shouldn't it?
{
$port = tie(*FH, 'Device::SerialPort', $ARGV[0]) or die "$ARGV[0]: $!";
$fh = \*FH; # as a GLOB
$fh = bless(\*FH, 'IO::Handle'); # or as an IO::Handle
}
print $fh "text"; # this works
print FH "text"; # …Run Code Online (Sandbox Code Playgroud) 我正在使用返回引用的现有代码,如下所示:
int &func()
{
static int i = 5;
return i;
}
Run Code Online (Sandbox Code Playgroud)
我想将错误情况返回为“NULL”,但当然 NULL 在按引用返回函数中不起作用。如果这返回一个指针我可能会这样做:
int *func()
{
static int i = 5;
if (!good)
return NULL;
else
return &i;
}
Run Code Online (Sandbox Code Playgroud)
除了转换为基于指针的返回值之外,是否有返回失败状态的最佳实践?
我想指示编译器使用如下代码展开一些循环。太长了,我不想复制粘贴。
#define 语句可以定义预处理器宏吗?
我试过这个:
#define foo \
#ifdef __GNUC__ \
#if __GNUC__ >= 8 \
#pragma GCC unroll 128 \
#pragma GCC ivdep \
#endif \
#endif \
#ifdef __clang__ \
#pragma clang loop vectorize(enable) interleave(enable) \
#endif
Run Code Online (Sandbox Code Playgroud)
但是当我foo在代码中使用时cpp显示它无效扩展为:
#ifdef 4 #if 4 >= 8 #pragma GCC unroll 128 #pragma GCC ivdep #endif #endif #ifdef __clang__ #pragma clang loop vectorize(enable) interleave(enable) #endif
#ifdef 4 #if 4 >= 8 #pragma GCC unroll 128 #pragma GCC ivdep #endif …Run Code Online (Sandbox Code Playgroud) 我正在编写一个封装父类的多个对象的子类,这样我就可以像向量一样调用函数,如下所示:
package OriginalClass;
sub new { return bless {bar => 123}, 'OriginalClass' }
sub foo { return shift->{bar}; }
1;
package NewClass;
use parent OriginalClass;
# Return a blessed arrayref of "OriginalClass" objects.
# new() would be called NewClass->new(OriginalClass->new(), ...)
sub new {
my $class = shift;
return bless \@_, 'NewClass';
}
# Vectorized foo(), returns a list of SUPER::foo() results:
sub foo
{
my $self = shift;
my @ret;
push @ret, $_->SUPER::foo() foreach @$self;
return @ret;
}
1;
Run Code Online (Sandbox Code Playgroud)
我不想 …
我在这里使用 @ikegami 帖子AUTOLOAD中的示例。我的RF::Component::Multi模块最近的CPAN 测试人员报告指出:
Bareword found where operator expected at .../RF/Component/Multi.pm line 102, near "s/^.*:://sr"
syntax error at .../RF/Component/Multi.pm line 102, near "s/^.*:://sr"
Run Code Online (Sandbox Code Playgroud)
代码如下,在 GitHub上。
use 5.xx?use vars '$AUTOLOAD'?Bareword found where operator expected at .../RF/Component/Multi.pm line 102, near "s/^.*:://sr"
syntax error at .../RF/Component/Multi.pm line 102, near "s/^.*:://sr"
Run Code Online (Sandbox Code Playgroud) 我注意到Parallel::Loops模块用作$_其 subref 的参数。这个问题与Parallel::Loops本身无关,而是与 coderef 调用约定有关。
这是他们的示例,请注意$_传递给子:
$pl->foreach( \@parameters, sub {
# This sub "magically" executed in parallel forked child
# processes
# Lets just create a simple example, but this could be a
# massive calculation that will be parallelized, so that
# $maxProcs different processes are calculating sqrt
# simultaneously for different values of $_ on different CPUs
# (Do see 'Performance' / 'Properties of the loop body' below)
$returnValues{$_} = …Run Code Online (Sandbox Code Playgroud)