Create a class in the normal way and use overload to overload the reference to produce the value in a string context:
c:\test>p1
package Enhanced::String;
use overload '""' => \&asString;
sub new {
my $class = shift;
return bless { string => shift }, $class;
}
sub substr{
return substr( $_[0]{ string }, $_[1], $_[2] )
};;
sub asString {
return $_[ 0 ]{ string }
};
package main;
my $obj = Enhanced::String->new( 'the string' );;
print $obj->asString;;
the string
print $obj;;
the string
print $obj->substr( 4, 3 );;
str
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|