in reply to setting and retrieving sub-hash elements in an object
A bit more consise, but at what gain?sub option { my ($self,$arg,$value) = @_; return $self->{options}->{$arg} unless $value; $self->{options}->{$arg} = $value; }
For your second question - sounds like you want a hash slice:
UPDATE: nope, that is not what you want - see Masem's answer.my %hash; @hash{('a'..'d')} = (1..4);
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:
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....sub foo { my ($self) = @_; }
The other item is lining up data structures correctly:
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.sub new { my ($class) = @_; my $self = { foo => 'bar', bar => 'maz', options => { anoption => 1, anotheroption => 'foo', option3 => 'barbar', }, }; return bless $self, $class; }
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)
|
---|