Given this program:
use strict;
use warnings;
my $zx_size = 32;
my $x = "$zx_size'h0";
Perl tells me this:
Name "zx_size::h0" used only once: possible typo at concat.pl line 7.
Use of uninitialized value $zx_size::h0 in string at concat.pl line 7.
Why?
It appears there are multiple ways to specify the namespace of a var. Are there others?
Is it possible to turn off this behavior?
The old package delimiter was a single quote '
which was originally used to ease transition to Perl for Ada programmers. It was replaced with ::
to be more readable and ease the transition of C++ programmers.
It is still supported for backwards compatibility, but you can wrap your scalar in {..}
to have it interpolate correctly.
my $x = "${zx_size}'h0";
or
my $x = "$zx_size\'h0";
The single quote character '
was used by earlier Perls to denote package scope in the same way as ::
, and it is still supported for backwards compatibility.
To do what you want, you'll need to use the ${}
syntax to tell Perl where the identifier ends and the literal begins:
"${zx_size}'h0"
Note that this is the same thing you would have to do if you wanted to the value of $zx_size
followed by any other literal character that is legal to appear in an identifier:
"${zx_size}foo"
Read perlmod. The very second paragraph. And no, there's no way to turn it off, at least for now. Theoretically, someone could write a no feature
pragma for it, but it's been that way for 20 years without causing too many problems...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With