Help for this page

Select Code to Download


  1. or download this
    my %h = ();
    foreach(@_) {
       $h{something} = $_; # changes the %h above every time
       push @something, \%h;  # puts the %h into @something multiple times
    +...
    }
    
  2. or download this
    my %h = ();
    foreach(@_) {
       $h{something} = $_;    # changes the %h above every time
       push @something, {%h}; # copies the accumulated changes into @somet
    +hing
    }
    
  3. or download this
    foreach( @_ ) {
        my %new_hash = (something => $_ ); # make a new hash
        push @something, \%new_hash; # push it onto the stack
    }
    
  4. or download this
    foreach(@_) {
        push @something, { something => $_ }; # make a new hash and push i
    +t onto @something!  Magic!
    }