Help for this page

Select Code to Download


  1. or download this
    my @array = ( 1, 2, 3 );
    
    for my $elem ( @array ){
        say $elem;
    }
    
  2. or download this
    my $aref = \@array;
    
  3. or download this
    ARRAY(0x9bfa8c8)
    
  4. or download this
    for my $elem ( @{ $aref } ){
        say $elem;
    }
    
  5. or download this
    my $x  = $array[0];
    
  6. or download this
    my $y = $aref->[1];
    
  7. or download this
    $array[1]  = "assigning to array element 2";
    
  8. or download this
    $aref->[1] = "assigning to array element 2";
    
  9. or download this
    my %hash = ( a => 1, b => 2, c => 3 );
    
    ...
    
        say "key: $key, value: $value";
    }
    
  10. or download this
    my $href = \%hash;
    
  11. or download this
    while ( my ( $key, $value ) = each %{ $href } ){
    
        say "key: $key, value: $value";
    }
    
  12. or download this
    my $x = $hash{ a };
    
  13. or download this
    my $y = $href->{ a };
    
  14. or download this
    $hash{ a }  = "assigning to hash key a";
    
  15. or download this
    $href->{ a } = "assigning to hash key a";
    
  16. or download this
    my @b = ( 1, 2, 3 );
    my $aref = \@b;
    ...
    for my $elem ( @b ){
        say $elem;
    }
    
  17. or download this
    99
    2
    3
    
  18. or download this
    $b[0] = 99;
    $aref->[0] = 99;
    
  19. or download this
    my @a = ( 1, 2, 3 );
    my %h = ( a => 1, b => 2, c => 3 );
    ...
    
    # assign a value to a single hash key through its ref
    $h->{ a } = 1;