Leslie Leslie - 5 months ago 31
Perl Question

Strawberry Perl not recognising special variable for OSNAME

I recently upgraded Strawberry Perl from version 5.14.1.1-32bit to 5.24.0-64bit on my PC running Windows 7. I have a perl script I run under both Windows and Linux, and when I was using the old version the command

use if $^O eq 'MSWin32' , 'Win32::Console::ANSI';


worked, but now that I've upgraded I get the error message

Unrecognized character \x0F; marked by <-- HERE after use if $<-- HERE near column9 at p:\bin\abc.pl line 31.


Does anyone know what changed, and how I can get the new version of Strawberry Perl to accept the command? Thanks in advance to all who respond.

Answer

Your code contains the Shift In control character (0x0F), also known as "Control-O", instead of the characters ^ and O. This works in older versions of Perl but was deprecated in version 5.20.0:

Literal control characters in variable names

This deprecation affects things like $\cT, where \cT is a literal control (such as a NAK or NEGATIVE ACKNOWLEDGE character) in the source code. Surprisingly, it appears that originally this was intended as the canonical way of accessing variables like $^T, with the caret form only being added as an alternative.

The literal control form is being deprecated for two main reasons. It has what are likely unfixable bugs, such as $\cI not working as an alias for $^I, and their usage not being portable to non-ASCII platforms: While $^T will work everywhere, \cT is whitespace in EBCDIC. [perl #119123]

As of 5.24.0, using a variable name containing non-graphical ASCII control characters results in a syntax error.