每次调用push()后添加索引

发布于 2024-10-18 01:04:23 字数 365 浏览 3 评论 0原文

我在数组上使用 Perl push,但每次我在数组上推送某些内容时,它也会推送该项目的索引。
我同时对 2 个数组执行相同的操作,其中一个按预期推送,但另一个则没有。
是什么导致了这种无法解释的行为?

if ($var->{color} == 1) {
    push @x, $var->{variable}.'-l';  
    push @y, $var->{variable}.'-p';
}
else {
    push @x, '__',
    push @y, '__',
}

y 具有预期的数据,但 x 没有。

I'm using the Perl push on an array, but every time I push something on the array, it also pushes the item's index as well.
I am doing the same action on 2 arrays at the same time, and one pushes as expected, but the other does not.
What could be causing this unexplained behavior?

if ($var->{color} == 1) {
    push @x, $var->{variable}.'-l';  
    push @y, $var->{variable}.'-p';
}
else {
    push @x, '__',
    push @y, '__',
}

y has the data as expected, but x does not.

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

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

发布评论

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

评论(1

故笙诉离歌 2024-10-25 01:04:23

你需要的是分号,而不是逗号:

push @x, '__';
push @y, '__';

You want semicolons, not commas here:

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