- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
1){ foreach my $a ($args[1..$argsize-1]) { -6ren">
我在 Perl 中有以下代码片段:
my $argsize = @args;
if ($argsize >1){
foreach my $a ($args[1..$argsize-1]) {
$a =~ s/(.*[-+*].*)/\($1\)/; # if there's a math operator, put in parens
}
}
执行时我得到“Use of unitialized value $. in range (or flip) , followed by Argument ""isn't numeric in array element at... 都指向 foreach 行。
有人可以帮我解读错误消息(并解决问题)吗?我有一个字符串数组@args。代码应该循环遍历第二个到第 n 个元素(如果存在的话),如果它们包含 +、- 或 *,则用 () 包围单个 args。
我不认为错误源于 args 中的值,我认为我以某种方式搞砸了范围......但是当 args 有 > 1 个元素时我失败了。一个例子可能是:
<"bla bla bla"> <x-1> <foo>
最佳答案
总而言之 - 您的 foreach 行 损坏了:
foreach my $a (@args[1..$argsize-1]) {
工作正常。这是因为您使用的是表示“标量值”的 $
而不是表示数组(或列表)的 @
。
如果您使用诊断
,您会得到;
Use of uninitialized value $. in range (or flip) at (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables.
To help you figure out what was undefined, perl will try to tell you the name of the variable (if any) that was undefined. In some cases it cannot do this, so it also tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program.
您可以通过以下方式重现此错误:
my $x = 1..3;
这实际上与您在这里所做的差不多——您正在尝试将一个数组值赋给一个标量。
这个问题有很多细节:
What is the Perl context with range operator?
但基本上:它将其视为范围运算符,就好像您正在处理文件一样。您将能够通过此运算符“作用于”文件中的特定行。
例如:
use Data::Dumper;
while (<DATA>) {
my $x = 2 .. 3;
print Dumper $x;
print if $x;
}
__DATA__
line one
another line
third line
fourth line
该范围运算符正在测试行号 - 因为您没有行号(因为您没有迭代文件)所以它出错了。 (但否则 - 它可能有效,但你会得到一些真的奇怪的结果;))
但我建议您以一种相当复杂的方式执行此操作,并(可能?)犯了一个错误,因为您的数组从 1 开始,而不是从零开始。
你可以改为:
s/(.*[-+*].*)/\($1\)/ for @args;
结果相同。
(如果您需要跳过第一个参数:
my ( $first_arg, @rest ) = @args;
s/(.*[-+*].*)/\($1\)/ for @rest;
但是运行时的错误是您输入的一些数据的结果。尽管如此,您在这里得到了什么:
use strict;
use warnings;
my @args = ( '<"bla bla bla">', '<x-1>', '<foo>' );
print "Before @args\n";
s/(.*[-+*].*)/\($1\)/ for @args;
print "After: @args\n";
关于perl - "Use of unitialized value $. in range (or flip)"试图用 Perl 告诉我什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31205292/
我是 C++ 的新手,我在使用这段代码时遇到了问题: string output_date(int day, int month, int year){ string date; if
所以我这样做了 tar cvzf test.zip FP 为了创建目录 FP 的 zip 但是,它会列出 zip 中的目录 FP/ FP/php/ FP/php/pdf/ FP/php/docs/ F
我正在尝试在 Swift、Xcode 7.3(所以是 Swift 2.2)中创建一个通用类,但我似乎无法让它通过编译器: protocol Struct1Protocol { } struct Str
我的测试用例是这样的: class FooTest extends PHPUnit_Framework_TestCase { /** @covers MyClass::bar */ f
我正在尝试将brew install wine作为使electron-builder工作的一步。但是我所能得到的只是以下响应: ==> Installing dependencies for wine
我这样做: string[,] string1 = {{"one", "0"},{"Two", "5"},{"Three","1"}}; int b = 0; for(int i = 0; i <=
我正在尝试使用 SetWindowsHookEx 键盘 Hook Notepad.exe。 如您所见,工作线程正在将其 ASCII 代码(即 wParam)发送到指定的服务器。 UINT WINAPI
我正在尝试将 ListView 实现到我的 Fragment 中,但无论我尝试什么,我都会得到一个 NullPointerException。我检查对象是否为 null 并记录是否为 null,看起来
我尝试在一行中对齐两个 div。使用 float left 属性,一切顺利。但是当我在 div 中使用图像时,它开始产生问题。 所以这是我的示例代码:- Some headi
我目前正在使用此代码来获取图像的灰度图像表示并以 (512, 370, 1) 的格式表示它大批。 img_instance = cv2.imread(df.iloc[i][x_col]) / 255.
总结 我正在创建一个简单的应用程序,它允许用户选择一个包含顶级窗口的进程。用户首先键入 native DLL(而非托管 DLL)的路径。然后用户键入将在 Hook 过程中调用的方法的名称。该方法不得返
我是一名优秀的程序员,十分优秀!