I seem to be having an issue compiling a perl script of mine on an older version of perl that I was hoping someone could help me with. The system that I originally wrote and compiled the perl file on without issue is using perl v5.16.3, the system that I am now currently trying to compile and run it on is using perl v5.8.5 which is where I think the problem lies. I know there was a bunch of changes made in v5.10 as to how ~~ was used. Is v5.10 the first version that actually used the ~~ operator?
The following is the code that I'm getting the syntax error on:
if (/$SEARCH/x ~~ @{$pids{$mPID}{$key}}){
and this is the error I'm getting:
syntax error at /sysadm/shared/ftp_search.pl line 310, near "/$SEARCH/x ~"
syntax error at /sysadm/shared/ftp_search.pl line 310, near "})"
and this is the surrounding code so you have a better idea of what's going on:
foreach my $mPID (keys %pids){
foreach my $key (keys %{$pids{$mPID}}){
if (/$SEARCH/x ~~ @{$pids{$mPID}{$key}}){
} else {
delete $pids{$mPID}{$key};
}
}
}
So basically, I have a hash of hashes and basically if the statement ends up not matching up it will delete it from the hash. I'm working on trying to get the perl on the server upgraded but still trying to get approvals. Am I correct in assuming that this is due to the perl version being used?
Thank you.
The smart match operator was added in 5.10.0, and will not work in any previous versions of perl. (perl 5.10.0 change log )
As a side note, the operator has been classified as "experimental" since 5.18.0, and relying on it is not recommended. (5.18.0 change log).
Smart match, added in v5.10.0 and significantly revised in v5.10.1, has been a regular point of complaint. Although there are a number of ways in which it is useful, it has also proven problematic and confusing for both users and implementors of Perl. There have been a number of proposals on how to best address the problem. It is clear that smartmatch is almost certainly either going to change or go away in the future. Relying on its current behavior is not recommended.