Help for this page

Select Code to Download


  1. or download this
    %hash = ( 
        name  => 'Rhesa',
    ...
        dog   => 'Spot',
        cat   => 'Stofje',
    );
    
  2. or download this
    %pets = (
        dog   => 'Spot',
        cat   => 'Stofje',
    );
    
  3. or download this
    %pets = (
        dog => $hash{dog},
        cat => $hash{cat},
    );
    
  4. or download this
    my @animals = qw( dog cat );
    my %pets;
    @pets{ @animals } = @hash{ @animals };
    
  5. or download this
    %pets = map { $_ => $hash{$_} }
            qw( dog cat );
    
  6. or download this
    sub hash_slice {
        my ($hr, @k) = @_;
    ...
    
    # use like this:
    %pets = hash_slice( \%hash, qw( dog cat ) );
    
  7. or download this
    @headers = qw(
        firstname lastname
    ...
        title bookcode isbn
        quantity
    );
    
  8. or download this
    # %orderline comes from the csv
    my $customer = Customer->find_or_create({
        firstname => $orderline{firstname},
        lastname  => $orderline{lastname},
    });