小编flo*_*ads的帖子

如何在Perl中处理子例程重新定义的错误

所以我有一个文件,简而言之就是这个问题......

#!/usr/bin/perl -w
package Foo;

use strict;
use POSIX;

...

sub remove {
  ...
}
...
Run Code Online (Sandbox Code Playgroud)

我得到一个错误,说子程序remove已被重新定义.我知道这个问题,remove在POSIX中有一个子程序.但是,我不知道如何处理它.这个问题通常如何解决?

perl warnings subroutine

13
推荐指数
3
解决办法
1万
查看次数

命令在类模板中的函数的专门化中是否重要

考虑类似......

template<typename T>
class Vector {
  ...
  bool operator==( const Vector<float> &rhs ) {
    // compare and return
  }

  bool operator==( const Vector<T> &rhs ) {
    // compare and return
  }
  ...
 };
Run Code Online (Sandbox Code Playgroud)

注意专业化如何高于非专业版.如果我将专业版本放在非专业版本之下,那么Vector<float>==比较仍然可以按预期工作吗?出于某种原因,我想我还记得,如果你在这个场景中使用下面的专业化,那么当编译器查看标题时,它将首先看到默认值,看它是否有效,并使用它.

c++ templates specialization template-specialization

3
推荐指数
1
解决办法
1336
查看次数

"全局符号需要显式包名称"的说明

我一直在学习Perl,每当我写一个非平凡的脚本时,我总会得到这个错误信息.我一直认为我对它有很好的理解,但我想我没有.这是一个草率马尔可夫链示例(未测试),下面的错误.

#!/usr/bin/perl -w

use strict;

sub croak { die "$0: @_: $!\n"; }


sub output {
  my %chains = shift;
  my @keys = keys %chains;

  my $index = rand($keys);
  my $key = $keys[$index];

  my $out_buf = $key;
  for (my $i = 0; $i < 100; ++$i) {
    my $aref = $chains{$key};
    my $word = @$aref[rand($aref)];
    $out_buf .= " $word";

    $key =~ s/.+ //;
    $key .= " $word";
  }
  print $out_buf, "\n";
}


sub get_chains {
  my %chains;
  my @prefixes …
Run Code Online (Sandbox Code Playgroud)

perl

3
推荐指数
1
解决办法
4万
查看次数

无法通过包"Heap"找到对象方法"add"

我不确定为什么perl没有认识到Heap的方法添加.获得问题标题中的消息.这是最相关的文件.

#!/usr/bin/perl -w

use strict;
use Util;
use Heap;
use HuffTree;

my $heap = Heap->new;
my $test = 3;
$heap->add($test); # <--------ERROR HERE-----------
Run Code Online (Sandbox Code Playgroud)
package Heap;

use strict;
use warnings;

use POSIX ();

sub new {
  my $class = shift;
  my $self = { "aref" => [""],
           "next" => 1,
           @_};
  bless $self, $class;
}


sub print {
  my $self = shift;
  my $next = $self->{"next"};
  my $aref = $self->{"aref"};
  print "array => @$aref\n";
  print "next => $next\n";
}


sub compare …
Run Code Online (Sandbox Code Playgroud)

perl package

0
推荐指数
1
解决办法
1100
查看次数