How does perl recognise end of variable?
For example, this code:
use warnings;
my $a = 10;
print "Value of a is $a:::";
Output:
Use of uninitialized value $a:: in concatenation (.) or string at tryprint.pl line 6.
Value of a is :
Why does it consider $a:: and not $a: or $a:::
This works:
print "Value of a is $a\:::";
prints:
Value of a is 10:::
                :: is used to print/access a variable from a package/symbol table. For eg, to access a scalar variable x in package abc, Perl uses  $abc::x where abc is the name of the symbol table and x is the variable.  Similarly, when you used $a:::, Perl thought there is a package whose name is 'a' and the variable name as :, and hence those error.
See this example below:
our $a = 10;
{
        my $a=20;
        print "lexical a is $a \n";
        print "Value of a is $main::a";
}
                        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