#!/usr/bin/perl # Copyright 2003-2026, Paul Johnson (paul@pjcj.net) # This software is free. It is licensed under the same terms as Perl itself. # The latest version of this software should be available from my homepage: # https://pjcj.net # Example stolen from overload documentation # __COVER__ changes s/^17 +3 +3/17 2 2/ # __COVER__ changes s/^(str +)3( tests/overloaded:17)/${1}2$2/ package two_face; sub new { my $p = shift; bless [@_], $p } use overload '""' => \&str, '0+' => \&num, fallback => 1; sub num {shift->[1]} sub str {shift->[0]} package main; my $seven = new two_face ("vii", 7); printf "seven=$seven, seven=%d, eight=%d\n", $seven, $seven+1; print "seven contains `i'\n" if $seven =~ /i/;