Thanks, Xavier and Bob, that looks much better.
Cheers, Jan Bob Showalter wrote on 21.07.2005: >Jan Eden wrote: >> Hi, >> >> I need to store a list of month names into a hash structure such that: >> >> $self->{monate}->{1}->{bezeichnung} = 'Januar' >> $self->{monate}->{2}->{bezeichnung} = 'Februar' >> etc. >> >> Until now, I have used the rather clumsy: >> >> @month_hash{1..12} = ("Januar", "Februar", "März", "April", "Mai", >> "Juni", "Juli", "August", "September", "Oktober", "November", >> "Dezember"); >> >> for (sort keys %month_hash) { $self->{monate}->{$_}->{bezeichnung} = >> $month_hash{$_}; } > >You don't need to sort the keys, you don't need the arrows between adjacent >braces, and you can use the 'for' modifier to make the statement a bit more >readable: > > $self->{monate}{$_}{bezeichnung} = $month_hash{$_} for 1..12; > >> >> The following did not work: >> >> @{$self->{monate}->{1 ..12}->{bezeichnung}} = ("Januar", "Februar", >> "März", "April", "Mai", "Juni", "Juli", "August", "September", >> "Oktober", "November", "Dezember"); >> >> Is there a better way to do it? These references are making my brain >> swirl. > >If you want to avoid using %month_hash and want to use a list initializer, >you could do something like: > > my $n = 0; > $self->{monate}{++$n}{bezeichnung} = $_ for qw/ > Januar Februar März April Mai Juni > Juli August September Oktober November Dezember > /; > -- A core dump is your computer's way of saying "Here's what's on my mind, what's on yours?" -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>