[Pdx-pm] Musings on operator overloading (was: File-Fu overloading)
Aristotle Pagaltzis
pagaltzis at gmx.de
Thu Mar 20 13:39:48 PDT 2008
Hi Aaron,
* Aaron Crane <perl at aaroncrane.co.uk> [2008-02-24 17:30]:
> Aristotle Pagaltzis writes:
> > My counterproposal, were it possible in Perl 5, which it
> > isn’t, would be something like this:
> >
> > my $dir = 'foo'; # no object at all!
> >
> > foreach my $fn (qw(bar baz bat)) {
> > my $file = path { $dir / $fn };
> > open my $fh, '<', $file or die "$!\n";
> > while(my $line = <$fh>) {
> > # ...
> > }
> > }
>
> With only a little fiddling, that does seem at least mostly
> possible to me.
Not really, I’m afraid – not with your approach either. The
problem is two-fold:
1. It’s temporally scoped, not lexically.
2. “No object at all” can’t be done in *reasonable* fashion.
In other words, it’s faintly similar, but due to the limited
semantics of Perl 5 it loses so much of its appeal that it’s
hardly worth the effort.
:-/
Neat hack, though. The solution may ultimately fall short, but
even the limited Perl 5 semantics can carry one surprisingly far
with some outside-the-box thinking. Nice.
Regards,
--
Aristotle Pagaltzis // <http://plasmasturm.org/>
More information about the Pdx-pm-list
mailing list