# Two-face Scalars # Put this in two_face.pm in your Perl library directory: package two_face; # Scalars with separate string and # numeric values. sub new { my $p = shift; bless [@_], $p } use overload '""' => \&str, '0+' => \&num, fallback => 1; sub num {shift->[1]} sub str {shift->[0]} # Use it as follows: require two_face; my $seven = two_face->new("vii", 7); printf "seven=$seven, seven=%d, eight=%d\n", $seven, $seven+1; print "seven contains 'i'\n" if $seven =~ /i/; # (The second line creates a scalar which has both a string value, and a numeric value.) This prints: seven=vii, seven=7, eight=8 seven contains 'i'