Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

james (1129)

  (email not shown publicly)


Journal of james (1129)

Wednesday May 30, 2001
04:52 AM

Perl 6? Yes Please!

[ #224 ]

I love Perl. It lets me get the job done, it is wonderful, it is fantastic, it is - at times - a headache. answered my question the other day but the sinking feeling in my gut hasn't gone away and its starting to get me down.

It was a simple problem really: I needed to dispatch a method from each of the objects in a list contained within another object.


foreach my $object ( @{ $self->objectlist() } ) {

However, due to a lack of dilligence on my part I was occasionally putting things into the list that didn't belong. Simple solution to that is stop doing it. Well, yes, but it wasn't just me, it was also other people using the classes that I was writing.

How I asked, other than an if construct examining the return value of ref() (which I don't think is all that elegant) can I determine if an object is blessed? The answer, as I now know, is pretty straightforward:

use Scalar::Utils qw ( blessed );

(Thanks Richard)

Problem solved. But still this pain in my gut. And why? Its because Perl is actually causing me to take more time here, than a language such as say, Java, or C++ would. While I'm not advocating those particular languages over Perl, what I'm saying is the concept of method signatures are time-saving.

Being able to say something like (note: this is not an assumption about what perl6 syntax may look like - I'm not qualified - so I'll leave it to Mr. Conway to interpret how it actually may appear):

sub addObject (MyClass $object) {
    push @{$self->{objectlist}}, $object;

and be more or less guaranteed to be having the right thing happen is a far easier thing (and therefore more desirable) than:

use Scalar::Utils qw ( blessed );

sub addObject {
    my $self = shift;
    my $object = shift;
    if (blessed($object) && $object->isa('MyClass')) {
        push @{$self->{objectlist}}, $object;

And the more I think about it, the less I think that I'm wrong, so I'm trying not to (think about it, that is).