Last active
August 4, 2020 00:22
-
-
Save adeishs/13e55c16955d995931696f3d1196971a to your computer and use it in GitHub Desktop.
Perl list slurp
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
#!/usr/bin/env perl | |
use strict; | |
use List::Util qw(any); | |
use Data::Dumper::Concise; | |
my %h = ( | |
k1 => { | |
s1 => 0, | |
s2 => 0, | |
}, | |
k2 => { | |
s1 => 0, | |
s2 => 0, | |
}, | |
); | |
%c = ( | |
a => ( any { $h{$_}{s1} } qw(k1 k2) ), | |
b => !$h{k1}{s1}, | |
); | |
=cut | |
Output: | |
a, b: { | |
a => "", | |
b => 1, | |
} | |
=cut | |
print "a, b: " . Dumper( \%c ); |
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
#!/usr/bin/env perl | |
use strict; | |
use List::Util qw(any); | |
use Data::Dumper::Concise; | |
my %h = ( | |
k1 => { | |
s1 => 0, | |
s2 => 0, | |
}, | |
k2 => { | |
s1 => 0, | |
s2 => 0, | |
}, | |
); | |
my %c = ( | |
b => !$h{k1}{s1}, | |
a => any { $h{$_}{s1} } qw(k1 k2), | |
); | |
=cut | |
Output: | |
b, a: { | |
a => "", | |
b => 1, | |
} | |
=cut | |
print "b, a: " . Dumper( \%c ); | |
# now, swap them | |
%c = ( | |
a => any { $h{$_}{s1} } qw(k1 k2), | |
b => !$h{k1}{s1}, | |
); | |
=cut | |
Output: | |
a, b: { | |
a => "", | |
} | |
=cut | |
print "a, b: " . Dumper( \%c ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment