Help for this page

Select Code to Download


  1. or download this
    %h1=( 1=>"one", 2 => "two", 3 => "three", 4 => "four");
    @set=(1, 3, 5, 7);
    
    my %h2;
    $h2{$_} = $h1{$_} for grep exists $h1{$_}, @set;
    
  2. or download this
    %h1=( 1=>"one", 2 => "two", 3 => "three", 4 => "four");
    @set=(1, 3, 5, 7);
    
    my %h2 = %h1;
    delete $h2{$_} for grep exists $h1{$_}, @set;