Bloodnok has asked for the wisdom of the Perl Monks concerning the following question:
I hope this node isn't a harbinger of things to come this year ... just when I thought I was beginning to understand something, along comes the fickle finger of fate to point out the following (AFAICT) anomaly: running this one-liner doesn't produce the expected fatal not an object error....
Deparse shows, AFAICT, that there's nothing untoward going on from a parsing POV...pointo1d@unforgiven:~/workspace/SVC-ArgsParser$ perl -Mstrict -we 'sub + can_it { $_[0]->can(qw/can/) } my $f = qw/fred/; $f->can(qw/isa/); c +an_it(qw/fred/)' pointo1d@unforgiven:~/workspace/SVC-ArgsParser$
Question is, am I, once again, missing something obvious ? I was expecting a fatal error, at the very least, from the $f->can(qw/isa/) statement - but self-evidently didn't get one ... from either of the potential sources !!perl -MO=Deparse -we 'use strict ; sub can_it { $_[0]->can(qw/can/) } +my $f = qw/fred/; $f->can(qw/isa/); can_it(qw/fred/)' BEGIN { $^W = 1; } sub can_it { use strict 'refs'; $_[0]->can('can'); } use strict 'refs'; my $f = 'fred'; $f->can('isa'); can_it 'fred'; -e syntax OK
FWIW, I'm running 5.8.8 on Ubuntu.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Arrgh, can() appears to work for non-object !!
by ysth (Canon) on Jan 07, 2009 at 11:23 UTC | |
by Bloodnok (Vicar) on Jan 07, 2009 at 11:29 UTC | |
by ysth (Canon) on Jan 07, 2009 at 11:32 UTC | |
by Bloodnok (Vicar) on Jan 07, 2009 at 11:39 UTC | |
by JavaFan (Canon) on Jan 07, 2009 at 12:44 UTC | |
by shmem (Chancellor) on Jan 07, 2009 at 12:39 UTC |