Skip to content

Instantly share code, notes, and snippets.

@phluid61
Last active July 20, 2017 02:52
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 phluid61/5a7307e0ff9d2b52ba5336466a121a06 to your computer and use it in GitHub Desktop.
Save phluid61/5a7307e0ff9d2b52ba5336466a121a06 to your computer and use it in GitHub Desktop.
hpush -- like 'push' for a hash
package hpush;
use base 'Exporter';
our @EXPORT = ('hpush');
use strict;
use warnings;
sub hpush (\%@) {
my $h = shift;
foreach (@_) {
$h->{$_} = 1;
}
}
1;
$ perl test.pl
1
1,2,3
1,2,3,5
$
use strict;
use warnings;
use hpush;
my %h = ();
hpush %h, 1;
print join(',', sort keys %h), "\n";
hpush %h, 2, 3;
print join(',', sort keys %h), "\n";
hpush %h, 1,3,5;
print join(',', sort keys %h), "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment