in reply to Re^3: Arrgh, can() appears to work for non-object !!
in thread Arrgh, can() appears to work for non-object !!

Does that mean that it's safe to infer that perl will, if it thinks it appropriate, treat all literals/string constants as class names ?

A user level that continues to overstate my experience :-))
  • Comment on Re^4: Arrgh, can() appears to work for non-object !!

Replies are listed 'Best First'.
Re^5: Arrgh, can() appears to work for non-object !!
by JavaFan (Canon) on Jan 07, 2009 at 12:44 UTC
    Does that mean that it's safe to infer that perl will, if it thinks it appropriate, treat all literals/string constants as class names ?
    No. It will only treat strings that start with a letter or underscore to be class names:
    $ perl -wE 'say "fred" -> can ("can")' Use of uninitialized value in say at -e line 1. $ perl -wE 'say "1fred" -> can ("can")' Can't call method "can" without a package or object reference at -e li +ne 1. $ perl -wE 'say " " -> can ("can")' Can't call method "can" without a package or object reference at -e li +ne 1. $ perl -wE 'say "f r e d" -> can ("can")' Use of uninitialized value in say at -e line 1. $
    But this "autocasting" is not surprising. Perl does that all the time. String can be numbers or regexes. Numbers can be strings. Floats can be integers, etc.
Re^5: Arrgh, can() appears to work for non-object !!
by shmem (Chancellor) on Jan 07, 2009 at 12:39 UTC

    No. That's only true for a Literal in Literal->method an only if method is in UNIVERSAL.