Henry Henry - 4 months ago 20
Perl Question

Why do I get the error 'Invalid range " B->" in transliteration operator' even though `tr` doesn't appear in my code?

I'm getting the following error when I run my Perl script:


Invalid range "B->" in transliteration operator at ./foo.pl line 249


However, line 249 is commented out, and I don't use the transliteration operator
tr
anywhere in my code.

Here is the relevant piece of my script. Line 249 is
# foreach (@projects)
, and as you can see, it has been commented out.

# Find the project name, hardware, and version from the archive given
$project = undef;
$hardware = undef;
$version = undef;
if (defined $testfarmDB){
my $idFile = `pwd`;
chomp $idFile;
$idFile .= "/$ENV{TESTDIR}/testrun.id";
y @filecontent = `cat $idFile`;
$filecontent[0] =~ /(\d+)/;
my $testRunID = $1;
$hardware = $testfarmDB->getTestRunModelName($testRunID);
$project = $testfarmDB->getTestRunProjectName2($testRunID);
$version = $testfarmDB->getTestRunSWRevisionName($testRunID);
}else{
die "Cannot connect to Database. Program terminated. \n";
}
print " Project = $project\n";
print " Model Type = $hardware\n";
print " Software Version = $version\n";

# Break up the path given to determine the project and version number
# foreach (@projects)
# {
# if ($archive =~ /($_)/i)
# {
# $project = $_;

# foreach my $hw (@hardwares)
# {
# if ($archive =~ /$hw/i)
# {
# $hardware = $hw;
# last;
# }
# }
# last;
# }
# }

$archive =~ /((?:\d+\.)+\w+)/;
# $version = $1;


How can I fix this?

mob mob
Answer

This:

 y @filecontent = `cat $idFile`;

y is an archaic synonym for the tr operator. Perl is searching for two more @ characters to complete the y@...@...@ statement, and it finds the second one in your comment section.