$value = $list[1] ~ s/\D//g;
Run Code Online (Sandbox Code Playgroud)
try1.pl第53行的语法错误,靠近"]〜"
由于编译错误,try1.pl的执行被中止.
我试图从第二个元素中提取数字@list
,并将其存储到$value
.
我comparefiles
在Perl中编写一个子程序,它从一个文件(f1
)中读取一行文本,然后f2
以正常O(n^2)
方式在另一个文件中搜索它.
sub comparefiles {
my($f1, $f2) = @_;
while(<f1>) {
# reset f2 to the beginning of the file
while(<f2>) {
}
}
}
sub someother {
open (one, "<one.out");
open (two, "<two.out");
&comparefiles(&one, &two);
}
Run Code Online (Sandbox Code Playgroud)
我有两个问题
f2
到上面注释中标记位置的文件开头?我有5个Perl文件,它们是我环境中5种不同状态的验证脚本.
他们每个人至少有几个子程序.
到目前为止,州的数量限制在5个,这些工作正常.但是现在,根据当前的设计,我有20个以上的环境状态,因此有20个Perl脚本.
我想将所有五个脚本移动到一个脚本中,该脚本将状态作为参数,并为5种不同的状态设置5个不同的子程序.
这样,当我需要为另一个状态添加验证时,我将只需要定义一个新的子例程而不是一个全新的Perl脚本.
问题在于它将意味着使用嵌套子例程(已知会遇到问题),或者展开子例程本身.
例如,
原始脚本
$ cat verify1.pl
sub a1 {
...
}
sub b1 {
...
}
a1(); b1(); a1();
$ cat verify2.pl
sub a2 {
...
}
sub b2 {
...
}
sub c2 {
...
}
a2(); b2(); c2(); a2();
$
Run Code Online (Sandbox Code Playgroud)
合并脚本
$ cat verify.pl
sub one {
...
}
sub two {
...
}
my ($arg) = @ARGV;
if ($arg == 1) {
one(); # should do what verify1.pl did
} …
Run Code Online (Sandbox Code Playgroud) 示例代码:
m1.pm
my $a;
my $b;
sub init {
$a = shift;
$b = shift;
}
sub printab {
print "a = -$a-\n";
print "b = -$b-\n";
}
1;
Run Code Online (Sandbox Code Playgroud)
m2.pm
my $a;
my $b;
sub init {
$a = shift;
$b = shift;
}
1;
Run Code Online (Sandbox Code Playgroud)
test.pl
use strict;
use warnings;
use m1;
use m2;
init('hello', 'world');
printab();
Run Code Online (Sandbox Code Playgroud)
跑:
$ perl test.pl
a = --
b = --
$
Run Code Online (Sandbox Code Playgroud)
会发生什么是init('hello', 'world')
调用映射到m2.pm
并初始化变量($a
和$b
).
这种做法很有意义,但我不明白为什么这些价值观无法获得test.pl …
我正在创建一个 Google Chrome 扩展程序,它根据提供的选项进行一些基本搜索。
这是到目前为止的样子
问题是侧面有很多不好看的空白区域,特别是因为这是一个弹出窗口并叠加在当前页面上。
如何确保弹出窗口使用所需的最小空间量?
perl ×4
file-io ×1
html ×1
javascript ×1
nested ×1
perl-module ×1
popup ×1
scripting ×1
subroutine ×1