H.Merijn Brand wrote: > Michael G Schwern: >> What I was thinking was something like: >> >> open my $fh, "<", $file or die $fh->error; > > this is *very* counter-intuitive. > After a fail, I expect $fh to be false. How do I call a method on an > undefined value? Welcome to the wonderful world of objects. -- Ruud perl -Mstrict -MData::Dumper -wle' my $value; # undef my $obj = bless \$value, "Foo"; print Dumper $obj; $obj->show; package Foo; use overload bool => \&_val; use overload q{""} => \&_val; use overload q{0+} => \&_val; sub show { print "<", $_ // "-undef-", ">" for @_; } sub _val { ${ $_[0] }; } ' $VAR1 = bless( do{\(my $o = undef)}, 'Foo' ); <-undef->Thread Previous | Thread Next