in reply to Re^4: OO design: returning string and/or special value
in thread OO design: returning string and/or special value

... vast majority of the time, the caller is going to want that value in plain old string format.... sometimes they want both string and special formats from the same call ...

How about just use good old wantarray to either:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "sub flexi { my ($str) = @_; ;; my ($string, $special) = map { uc, scalar reverse } $str; ;; return wantarray ? (string => $string, special => $special) : $string ; } ;; my %hash = flexi('foobar'); dd \%hash; ;; my $string = flexi('foobar'); dd $string; " { special => "raboof", string => "FOOBAR" } "FOOBAR"
or:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "sub flexi { my ($str) = @_; ;; my ($string, $special) = map { uc, scalar reverse } $str; ;; return wantarray ? ($string, $special) : $string ; } ;; my $string1 = flexi('foobar'); dd $string1; ;; my ($string2, $special) = flexi('foobar'); dd $string2, $special; " "FOOBAR" ("FOOBAR", "raboof")


Give a man a fish:  <%-{-{-{-<