http://www.perlmonks.org?node_id=1225755

catfish1116 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to figure out the chr() function, and have written a few lines of code:

#!/usr/bin/perl use v5.12; use warnings; $alpha = chr(65); say "This is what Alpha looks like $alpha". "\n";

And I'm getting this error

Global symbol "$alpha" requires explicit package name at ./Page_34 li +ne 5. Global symbol "$alpha" requires explicit package name at ./Page_34 lin +e 6.

What package is it looking for? TIA catfish

Replies are listed 'Best First'.
Re: chr() function
by LanX (Cardinal) on Nov 13, 2018 at 21:53 UTC
    You have strict activated when using 5.12.

    Write my $alpha = ...

    Perl can't tell if it's a private (my) or global package (our) variable.

    So it takes a guess and asks you to make it clear by prepending a name space.

    our $var is basically an alias of the fully qualified $Pkg::var with the current package at declaration time.

    And yes this error message is confusing because nowadays most declarations are done with my , which doesn't have a name space.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Thank you sir !
A reply falls below the community's threshold of quality. You may see it by logging in.