В сообщении от 29 Март 2005 01:08 Alexandre Jousset написал(a):
>  Hey all...
>
> Vladi Belperchinov-Shabanski wrote:
> [snip...]
>
> > and 'hidden loop' one:
> >
> >    @a = ( 'E1', 'E2', 'E3', 'En' );
> >    $a = 1;
> >    map{ $a = { $_ => $a } } reverse @a;
> >    print Dumper( $a );
>
>  The problem with this one is that by doing this you 
> s. e.g. :
>
> @a = ( 'E1', 'E2', 'E3', 'En' );
> $a = 1;
^^^ destroy existing hash

> map{ $a = { $_ => $a } } reverse @a;
>
> @a = ( 'E1', 'Ex', 'Ey', 'Ez' );
> $a = 1;
> map{ $a = { $_ => $a } } reverse @a;
> print Dumper( $a );



use Data::Dumper;

@a = ( 'E1', 'E2', 'E3', 'En' );
$a = 1;
map{ $a = { $_ => $a } } reverse @a;

@a = ( 'E1', 'Ex', 'Ey', 'Ez' );
$b = \ $a->{E1}->{E3} ; # a new branch
map{ $$b = { $_ => $$b } } reverse @a;
print Dumper( $a );


gives:

$VAR1 = {
          'E1' => {
                    'E2' => {
                              'E3' => {
                                        'En' => 1
                                      }
                            },
                    'E3' => {
                              'E1' => {
                                        'Ex' => {
                                                  'Ey' => {
                                                            'Ez' => undef
                                                          }
                                                }
                                      }
                            }
                  }
        };

-- 
vad
  • ... Zhuang Li
    • ... Jeff Yoak
    • ... Uri Guttman
      • ... Aaron Sherman
        • ... Uri Guttman
    • ... Vladi Belperchinov-Shabanski
      • ... Alexandre Jousset
        • ... Суханов Вадим
          • ... Alexandre Jousset
    • ... Ton Hospel
      • ... Yitzchak Scott-Thoennes
    • ... Yitzchak Scott-Thoennes
      • ... Alexandre Jousset
        • ... Yitzchak Scott-Thoennes
          • ... Alexandre Jousset
    • ... Andrew Pimlott
      • ... Alexandre Jousset
        • ... Andrew Pimlott

Reply via email to