RE: join() and split() to respect string overload operations
[email protected] ("Jan Dubois")
| Newsgroups | perl.perl5.porters |
|---|---|
| Organization | ActiveState Software Inc |
| Message-ID | <[email protected]> |
On Mon, 07 Jun 2010, Paul LeoNerd Evans wrote:
> Now create a string-like object with well-behaved operator overload for
> concat, and observe you cannot still preserve the following identities:
>
> my $str = StringLike->new("Foo");
>
> substr( $str . "x", 0, len $str ) eq $str
> substr( "x" . $str, 0, 1 ) eq $str
>
> substr( $str, 0, 1 ) . substr( $str, 1 ) eq $str
I don't quite get how this would not work as long as you also have a
well-behaved overload for 'eq' and '""'. Or would these identities also be
broken:
substr( $str . "x", 0, len $str ) eq "$str"
substr( "x" . $str, 0, 1 ) eq "$str"
substr( $str, 0, 1 ) . substr( $str, 1 ) eq "$str"
If these work, but yours don't, then I wouldn't consider the complete
set of overloads to be self-consistent. If the these later identities
are broken as well, could you give an example of how to do it?
Cheers,
-Jan