Cumbersome, yes - but it is good style. If you don't really care about others understanding your code (which you should), you could opt for something like:
sub option { my ($self,$arg,$value) = @_; return $self->{options}->{$arg} unless $value; $self->{options}->{$arg} = $value; }
A bit more consise, but at what gain?

For your second question - sounds like you want a hash slice:

my %hash; @hash{('a'..'d')} = (1..4);
UPDATE: nope, that is not what you want - see Masem's answer.

UPDATE (about an hour of reflection):

To elaborate more - i would avoid using shift like you do. I have been known to do that from time to time, but it is sheer laziness on my behalf when i do.

For serious code, i really tend to use:

sub foo { my ($self) = @_; }
in case i need to (and usually do) supply more arguments. There are exceptions, such as default values or attaching comments to each argument, but for the most part....

The other item is lining up data structures correctly:

sub new { my ($class) = @_; my $self = { foo => 'bar', bar => 'maz', options => { anoption => 1, anotheroption => 'foo', option3 => 'barbar', }, }; return bless $self, $class; }
A lot easier for the eyes to parse! You can indent pretty much however you want, mine is just one way, but always remain consistent in how you do it.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

In reply to (jeffa) Re: setting and retrieving sub-hash elements in an object by jeffa
in thread setting and retrieving sub-hash elements in an object by Amoe

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.