我有一个程序,我从较旧的计算机下载到较新的计算机.它有以下代码片段:
#!/bin/perl -w use strict; $[ = 1; # set array base to 1 $,= ' '; # set output field separator $\ = "\n"; # set output record separator
但是,当我尝试运行该脚本时,我收到以下错误消息:
Use of assignment to $[ is deprecated at ./test.pl line 5.
有关如何解决此问题的任何想法?
我使用的是以下版本的perl:
This is perl 5,version 16,subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
解决方法
不推荐使用$[,不推荐使用和
all but disallowed.请参阅
it in perlvar(在
Deprecated and Removed Variables部分)并查看已移动的核心
arybase.
但是,如果必须,您可以禁用此特定warning category
use strict; use warnings; # Restrict the scope as much as possible { no warnings 'deprecated'; $[ = 1; # ... }
现在它不会打印出那个警告,它会起作用,因为它仍然是合法的.
请注意,这也会更改其他偏移量,例如字符串,但还不包括其他偏移量.这是一个非常非常古老的“功能”,请阅读文档.
如果可能的话,我强烈建议重写脚本.