Help for this page

Select Code to Download


  1. or download this
    # method 1 - always use an array:
    while (my @values = fetchrow_array()){
      my $hash = ($values[0] => [ $values[1] ]);
      push (@{$hash{$values[0]}}, values[2])
    }
    
  2. or download this
    # method 2 - switch scalars to arrays dynamically (good for other
    # cases, not so good for yours, here for completeness only)
    ...
        $hash{$values[0]} = [ $hash{$values[0]} ];
    }
    push @{$hash{$values[0]}}, $hash{$values[2]};