Set::Scalar::Valued - valued sets


Set::Scalar::Valued - valued sets


    use Set::Scalar::Valued;
    $s = Set::Scalar::Valued->new;
    $s->insert(a => 12, 'b c' => $d);
    $s->delete('b c' => $d);
    $t = Set::Scalar->new(x => $y, y => $z);


Valued sets are an extension of the traditional set concept. In addition to a member just existing in the set, the member also has a distinct value. You can think of this a combination of a traditional set and a Perl hash.

The used methods are as for the traditional of Set::Scalar, with the difference that when creating (new()) or modifying (insert(), delete(), invert()), you must supply twice the number of arguments: the member-value pairs, instead of just the members. Note, though, that in the current implementation of delete() the value half is unused, the deletion is by the member. In future implementation this behavior may change so that also the value matters.

There are a couple of additional methods:

    %ve = $s->valued_members;

which returns the member-value pairs, and

    @v  = $s->values;

which returns just the values (in the same order as the members() method would return the members), and

    $v  = $s->value($member);

which returns the value of the member.

The display format of a valued set is the member-value pairs separated by `` => '', the pairs separated by ``, '' and enclosed in curly brackets {}.


Jarkko Hietaniemi <>

 Set::Scalar::Valued - valued sets