1 Eintrag, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use Text::ParseWords ();
my %_const_handlers = (
q => sub {
if ($_[0] =~ m/^\([ \.\d\w]*\)$/) {
my $str = substr $_[0], 1, length ($_[0]) - 2;
my @elems = Text::ParseWords::quotewords (qr/\s+/, 0, $str);
# { local $"="+"; print "[@elems]\n"; }
if (defined $elems[1] and $elems[1] eq "..") {
@elems = $elems[0] .. $elems[2];
}
return ->new (@elems) || $_[1];
} else {
return $_[1];
}
},
);
sub import { overload::constant %_const_handlers; }
Quotekabel@linux:~/progs/perl/set> cat test.pl
use strict;
use Set::Scalar;
my $s1 = '(1 .. 12)';
my $s2 = '(1 2)';
# differenz
my $s3 = $s1 - $s2;
print $s3, $/;
# unique elements (rechtsassoziativ)
$s3 = $s1 / '(2 .. 13)' / '(4)';
print $s3, $/;
# proper subset
if ($s2 < $s1) {
print "yes", $/;
}
print STDOUT '(a .. z)', $/;
kabel@linux:~/progs/perl/set> perl -w test.pl
[(1 .. 12)+(1 .. 12)+q]
[(1 2)+(1 2)+q]
[(2 .. 13)+(2 .. 13)+q]
[(4)+(4)+q]
[yes+yes+q]
[(a .. z)+(a .. z)+q]
(10 11 12 3 4 5 6 7 8 9)
(1 13 4)
yes
(a b c d e f g h i j k l m n o p q r s t u v w x y z)
kabel@linux:~/progs/perl/set>
1 Eintrag, 1 Seite |