somebody to remember this article about overloading at perl.com?

i patched Set::Scalar a little bit some time ago to support '{1 2 3}' and '{1 .. 3}' notions. code is broken, but should suffice for some own experiments ... just put it somewhere at the top of it, and off you go. beware to throw code far, far away afterwards ;-) (where no code has gone before)

use overload; my %_const_handlers = ( q => sub { if ($_[0] =~ m/^\{.*\}$/) { my $str = substr $_[0], 1, length ($_[0]) - 2; my @elems = split /\s+/, $str; if (defined $elems[1] and $elems[1] eq "..") { @elems = $elems[0] .. $elems[2]; } return __PACKAGE__->new (@elems) || $_[1]; } else { return $_[1]; } }, ); sub import { overload::constant %_const_handlers; }

kabel@linux:~> perl -w -MSet::Scalar my $some_ints = '{1 .. 4}'; my $other_ints = '{3 .. 8}'; my $all_ints = $some_ints + $other_ints; print '[', join( ', ', sort $all_ints->members ), "]\n"; print $Set::Scalar::VERSION, " ", $], $/; [1, 2, 3, 4, 5, 6, 7, 8] 1.17 5.008 kabel@linux:~>


In reply to Re: Set::Scalar saves you from hash acrobatics by kabel
in thread Set::Scalar saves you from hash acrobatics by princepawn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.