#!/usr/bin/perl -T # implicit BEGIN blocks cause require and importing use strict; use warnings; # here we define the object { # creates a namespace package Animal::Hog; # creates, but does not initialize, a lexical my $sound1; # creates, but does not initialize, a strict-friendly global our $sound2; # creates the function sub new { my $class = shift; bless {}, $class; } # creates the function, closing over the lexical $sound1 # ... and binding to the symbol $Animal::Hog::sound2 sub sound { my $self = shift; print $sound1, "\n"; print $sound2, "\n"; return 'knor'; } } #### #!/usr/bin/perl -wT # call object method Animal::Hog->sound(); { # assigns to the variable my $sound1 = "knor1"; # assigns to the variable our $sound2 = "knor2"; }