Perl 的 $ 是多少?变量为?

发布于 2024-08-20 10:56:59 字数 280 浏览 4 评论 0原文

有谁知道以下代码片段中的 $; (第一个分割函数参数)是什么:

      local(@a) = ();
      local($i) = 0;
      for ($i = 0; $i < $d; $i++) {
         @a = split($;, @b[$i]);
         $c     = @a[0];
      }

除了 for 循环之外,在脚本中的任何位置都找不到标量。

任何帮助表示赞赏。

Does any 1 have any idea what is $; (first split function argument) in the following code snippet:

      local(@a) = ();
      local($i) = 0;
      for ($i = 0; $i < $d; $i++) {
         @a = split($;, @b[$i]);
         $c     = @a[0];
      }

The scalar is not found any where in the script other than in the for loop.

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

允世 2024-08-27 10:56:59

Perl 的特殊变量记录在 perlvar 中,包括 $ ;

$SUBSEP

$;

多维数组模拟的下标分隔符。如果您将哈希元素称为

<前><代码>$foo{$a,$b,$c}

这确实意味着

$foo{join($;, $a, $b, $c)}

但不要放

@foo{$a,$b,$c} # 一个切片——注意 @

这意味着

<代码>($foo{$a},$foo{$b},$foo{$c})

默认为"\034",与awk中的SUBSEP相同。如果您的密钥包含二进制数据,则 $; 可能没有任何安全值。 (助记:逗号(语法下标分隔符)是一个分号。是的,我知道,这很蹩脚,但是 $, 已经被用来表示更重要的东西。)

考虑使用“真正的”多维数组,如 perllol 中所述。

我们可以猜测为什么要使用它(例如,也许@b包含一些散列的键),但是知道@b是如何创建的会让我们提供更有帮助的答案。

另请注意,@b[$i]@a[0] 可能应该是

$b[$i]

and

$a[0]

。使用前导 @ 时,它们是单元素数组切片,但使用 $ 时,它们是简单标量。

Perl's special variables are documented in perlvar, including $;

$SUBSEP

$;

The subscript separator for multidimensional array emulation. If you refer to a hash element as

$foo{$a,$b,$c}

it really means

$foo{join($;, $a, $b, $c)}

But don't put

@foo{$a,$b,$c}  # a slice--note the @

which means

($foo{$a},$foo{$b},$foo{$c})

Default is "\034", the same as SUBSEP in awk. If your keys contain binary data there might not be any safe value for $;. (Mnemonic: comma (the syntactic subscript separator) is a semi-semicolon. Yeah, I know, it's pretty lame, but $, is already taken for something more important.)

Consider using "real" multidimensional arrays as described in perllol.

We could guess about why it's being used (e.g., maybe @b contains some hash's keys), but knowing how @b is created would let us provide more helpful answers.

Note also that @b[$i] and @a[0] should probably be

$b[$i]

and

$a[0]

instead. With the leading @, they're single-element array slices, but with $, they're simple scalars.

一身骄傲 2024-08-27 10:56:59

Perl 特殊变量在 perlvar 中列出。

The Perl special variables are listed in perlvar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文