M
Michele Dondi
First of all please let me apologize for the (most probably) badly
chosen subject line...
I found out that qr// returns a *blessed* reference into the Regexp
class, allowing one to do things like
#!/usr/bin/perl -l
use strict;
use warnings;
sub Regexp::matches {
my $re=shift;
grep /$re/, @_;
}
print for qr/[a-z]+$/->matches(qw/foo bar1 baz baz2/);
__END__
Now, rumors insist on the fact that basically in Perl6 everything will
be an object. OTOH I wonder why in current perl references are not
automatically bless()ed, so that one could do something like this
#!/usr/bin/perl -l
use strict;
use warnings;
sub HASH::keys { keys %{shift()} };
print for { A => 1, B => 2, C => 3 }->keys;
__END__
Of course I understand that technically some difficulties may arise
because (things like) hashrefs are commonly used to implement generic
classes, but then wouldn't add such a support as that hinted above
require just some more bits of magic a' la Perl?
Michele
chosen subject line...
I found out that qr// returns a *blessed* reference into the Regexp
class, allowing one to do things like
#!/usr/bin/perl -l
use strict;
use warnings;
sub Regexp::matches {
my $re=shift;
grep /$re/, @_;
}
print for qr/[a-z]+$/->matches(qw/foo bar1 baz baz2/);
__END__
Now, rumors insist on the fact that basically in Perl6 everything will
be an object. OTOH I wonder why in current perl references are not
automatically bless()ed, so that one could do something like this
#!/usr/bin/perl -l
use strict;
use warnings;
sub HASH::keys { keys %{shift()} };
print for { A => 1, B => 2, C => 3 }->keys;
__END__
Of course I understand that technically some difficulties may arise
because (things like) hashrefs are commonly used to implement generic
classes, but then wouldn't add such a support as that hinted above
require just some more bits of magic a' la Perl?
Michele