I expected 3rd way to work just like the others, by creating a my variable in main.
If you use
Devel::Symdump, you'll see that
my variables, aren't actually in the main package, they are local to the block.. The list outputted by the following code, shows all scalar symbols in the main package.
#! /usr/bin/perl
use strict;
use Devel::Symdump;
my $obj = Devel::Symdump->new('main');
my $var1 = 'var1';
our $var2 = 'var2';
foreach($obj->scalars){
print "$_\n";
}
__OUTPUT__
...Builtin Vars...
main::var2
...More Builtin Vars...
Update: Fixed misplaced sentence fragment.