I don't see how it could be different for different objects. Here is the structure of the module (from Conway's book):
use strict; use warnings; package Music; use Carp; our $AUTOLOAD; { my %_attrs = ( _name => undef, _artist => undef, _publisher => undef, _ISBN => undef, _tracks => undef, _rating => undef, _room => undef, _shelf => undef, ); sub _accessible { exists $_attrs{$_[1]}} } { my $_count = 0; # These are class methods. sub get_count { $_count } # This method is global t +o the program my $_incr_count = sub { ++$_count }; sub new # Constructor called "new" { my ($class) = @_; # Gets class passed to co +nstructor $_incr_count->(); bless { # Creates a blessed referen +ce... _name => $_[1], # _artist => $_[2], # _publisher => $_[3], # _ISBN => $_[4], # _tracks => $_[5], # Simply assigns hash +key variables to _room => $_[6], # the arguments passed t +o the constructor. _shelf => $_[7], # _rating => $_[8], # _read_count => 0, }, $class; # in this class } } sub AUTOLOAD { my ($self) = @_; $AUTOLOAD =~ /.*::get(_\w+)/ or croak "No such method: $AUTOLOAD"; $self->_accessible($1) or croak "No such attribute: $1"; $self->{_read_count}++; return $self->{$1} } sub get_location {($_[0]->{_room}, $_[0]->{_shelf}) } sub set_location { my ($self, $shelf, $room) = @_; $self->{_room} = $room; $self->{_shelf} = $shelf; } sub set_rating { my ($self, $rating) = @_; $self->{_rating} = $rating; } 1;

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop";
$nysus = $PM . $MCF;
Click here if you love Perl Monks


In reply to Re: Re: Need help understanding variable scope in modules by nysus
in thread Need help understanding variable scope in modules by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.