Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
Created May 1, 2017 04:30
Show Gist options
  • Select an option

  • Save glinesbdev/34a60bfe268b9b3650025ecbea33a1c5 to your computer and use it in GitHub Desktop.

Select an option

Save glinesbdev/34a60bfe268b9b3650025ecbea33a1c5 to your computer and use it in GitHub Desktop.
Sub to create hash
#!/usr/bin/perl
use strict;
use warnings;
sub create_hash {
my %hash;
my @keys = "@{$_[0]}";
my @values = "@{$_[1]}";
foreach my $i (0 .. $#keys) {
$hash{$keys[$i]} = $values[$i];
}
return %hash;
}
my %hash = create_hash(["do", "re", "mi"], ["first", "second", "third"]);
while ((my $key, my $value) = each %hash) {
print "$key => $value\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment