[ create a new paste ] login | about

Link: http://codepad.org/BVMVmfw7    [ raw code | output | fork ]

drbaggy - Perl, pasted on Dec 18:
1
2
3
4
5
6
7
8
9
10
11
package Set::NoReplace;

sub new { bless {}, shift; }
sub add { $_[0]{$_[1]} = 1 unless exists $_[0]{$_[1]}; return $_[0]; }
sub del { $_[0]{$_[1]} = 0 if     exists $_[0]{$_[1]}; return $_[0]; }
use overload '""' => sub { return join ', ', sort grep { $_[0]{$_} } keys %{$_[0]}; };

my $x = Set::NoReplace->new;
print $x->add( 3 )->add( 5 )->add( 1 ), "\n";
print $x->del( 3 ),"\n";
print $x->add( 3 )->add( 7 ),"\n";


Output:
1
2
3
1, 3, 5
1, 5
1, 5, 7


Create a new paste based on this one


Comments: