in reply to bless with => separated args
Run this, and you'll note that the object is stringified during the print as expected.my $obj = Stringy->new( 'the look' ); my $counter = 0; for my $it ( a1 => $obj => 2 => 3 => 4, 5 ) { $counter++; print "iteration: $counter "; print "with (" . $it . ")"; print "\n"; } #------------------------------------------------------- package Stringy; use strict; use overload ( '""' => \&toString, ); 1; sub new { my $class = shift; my $self = { appearance => shift, }; return bless $self, $class; } sub toString { my $self = shift; print "[toString called] "; return $self->{appearance}; }
Comment out the 'print "with...' line, and you will note that the object is never stringified, not even by the => operator in the for (...) list.
|
|---|