Skip to content

Instantly share code, notes, and snippets.

@heypano
Last active July 31, 2017 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heypano/6498755 to your computer and use it in GitHub Desktop.
Save heypano/6498755 to your computer and use it in GitHub Desktop.
Set multiple keys of a hash ref to 1 without a loop
#! /usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
my %hash = (a => 1, b => 1, c => 1);
my $hashref = \%hash;
my @keys = ('d','e','f','g','h','i');
@$hashref{@keys}=(1)x(@keys);
print Dumper($hashref);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment