How do I resolve the & ldquo; The use of the assignment to $ [is obsolete & rdquo;


I have a program that I downloaded from an older computer to a newer one. It has the following snippet of code:

#!/bin/perl -w

use strict;

$[ = 1;    # set array base to 1
$, = ' ';    # set output field separator
$\ = "\n";    # set output record separator

However, when I try to run the script I get the following error message:

Use of assignment to $[ is deprecated at ./ line 5.

Any idea on how to resolve this?

I am using the following version of perl:

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi

The use of $[ has been discouraged, deprecated, and all but disallowed. See it in perlvar (it is in Deprecated and Removed Variables section) and see the core arybase where it's been moved.

Still, if you must, you can disable this particular warning category

use strict;
use warnings;

# Restrict the scope as much as possible
    no warnings 'deprecated';
    $[ = 1;

    # ...

Now it will not print that warning, and it will work since it is still legal.

Note that this also changes other offsets, for strings for example, but not yet some others. It is a very, very old "feature," please read the documentation.

I'd strongly recommend rewriting the script, if at all possible.