Last active
July 20, 2017 02:52
-
-
Save phluid61/5a7307e0ff9d2b52ba5336466a121a06 to your computer and use it in GitHub Desktop.
hpush -- like 'push' for a hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hpush; | |
use base 'Exporter'; | |
our @EXPORT = ('hpush'); | |
use strict; | |
use warnings; | |
sub hpush (\%@) { | |
my $h = shift; | |
foreach (@_) { | |
$h->{$_} = 1; | |
} | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ perl test.pl | |
1 | |
1,2,3 | |
1,2,3,5 | |
$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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