Home > Software design >  $* is no longer supported as of Perl 5.30
$* is no longer supported as of Perl 5.30

Time:02-14

We are moving from an old unix server with perl 5.8.8 to a new server with Perl 5.32. We have a script that starts with following lines:

eval "exec /usr/local/bin/perl -S $0 $*"    
    if $running_under_some_shell;
                        # this emulates #! processing on NIH machines.    
                        # (remove #! line above if indigestible)

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_] =)(.*)/ && shift;    
                        # process any FOO=bar switches

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

The script doesn't work. For the line "eval "exec /usr/local/bin/perl -S $0 $*"" we get:

$* is no longer supported as of Perl 5.30 at /usr/local/ccmngr/bin/check_log.pl line 12. 

If I remove the $* from eval line, we get the following for line $[ = 1;:

Assigning non-zero to $[ is no longer possible at /usr/local/ccmngr/bin/check_log.pl line 20.

If anybody has an idea and like to share, it will be great help.

CodePudding user response:

These two should not have been used for a while.

Related to that use of $*, perlrun for -S explains its convoluted usage and rationale. In short,

Typically this is used to emulate #! startup on platforms that don't support #!.

So I'd try first to just get rid of that line since reasons for it may be entirely historical, and give it a normal #!/path-to-perl, or if you needed to trigger the version of Perl that is first on your path (what doesn't seem to be the case) better use /usr/bin/env. See the linked docs.

As for $[, the perlvar for $[ says

This variable stores the index of the first element in an array, and of the first character in a substring. The default is 0, but you could theoretically set it to 1 ... As of Perl v5.16.0, it is implemented by the arybase module.

However, even as the quote above is from the most recent perldoc, the arybase isn't available anymore, neither as core nor via CPAN. One can always get the package from CPAN (the most recent version appears to be for 5.28) and install it and keep fingers crossed ... but that's not really promising. Instead, Array::Base does exist and work per its synopsis (checked on 5.32).

(I'd really rather recommend to use 0-based arrays in a Perl script but I don't know whether it's feasible to change that in your program.)

More, you may well need to (carefully) rework quite a bit more, jumping from 5.8 to 5.32.


It may be that the compiler is confusing that $* as a (removed) regex variable and complaining about that, since $* there is meant to be used by csh (so perl shouldn't have a problem with it). If true, that may be possible to fix somehow.

But regardless, it's far better to just remove it if it's not anymore needed all these years later.

CodePudding user response:

If you have vital code that is written in Perl, then you shouldn't be running it using the system Perl - as you've seen, this can prevent you from upgrading your operating system.

Instead, you should have your own installation of Perl which is a version known to work with your code. perlbrew is a handy tool for doing this.

(But, yes, you should also look at using code that isn't quite as old as that!)

  • Related