develooper Front page | perl.perl5.porters | Postings from June 2009

Re: improving $! usability

Thread Previous
From:
Dr.Ruud
Date:
June 21, 2009 16:35
Subject:
Re: improving $! usability
Message ID:
20090621221502.23031.qmail@lists.develooper.com
Dr.Ruud wrote:
> 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.

Though defined() is tougher:

perl -Mstrict -MData::Dumper -wle'

   my $value;  # undef
   my $obj = bless \$value, "Foo";

   print Dumper $obj;
   print "defined:", defined $obj;
   print $obj;

package Foo;
use overload nomethod => \&_val;
sub _val { ${ $_[0] } }
'
$VAR1 = bless( do{\(my $o = undef)}, 'Foo' );

defined:1
Use of uninitialized value in print at -e line 9.


Can "//" obey overloading?

-- 
Ruud

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About