in reply to Perl Module - take in a String, output object
Extremely silly, but amusingly short :)
#!/usr/bin/perl -wl use strict; my @a=0..1e3; # Set higher than any reasonable message number my @list = ("1, 3, 5-7", "1-5, 2, 4", "1-3, 2-5"); for (@list){ my %h; s/-/../g; $h{$_}++ for @a[(eval $_)]; print join " ", sort {$a<=>$b} keys %h; }
Output:
1 3 5 6 7 1 2 3 4 5 1 2 3 4 5
This relies on Perl interpreting your format (once dashes are replaced by double dots) as array subscripts.
|
|---|