http://qs321.pair.com?node_id=1212575


in reply to Perl Syntax - What's the difference?

> Can't locate object method "ymd" via package "2008-08-18"

probably you have code where you use ymd without brackets?

DB<4> $a="2008-08-18" DB<5> ymd $a Can't locate object method "ymd" via package "2008-08-18" (perhaps you + forgot to load "2008-08-18"?) at (eval 10)[/usr/share/perl/5.18/perl +5db.pl:732] line 2.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Perl Syntax - What's the difference?
by Corion (Patriarch) on Apr 09, 2018 at 12:08 UTC

    There is no code (as posted) where ymd $foo is shown.

    The error message occurs for any string that gets used as a class/object without being blessed.

      The OP said the only thing he changed where "underscore introduced in column names" , so consequently I expected some side effects in code he is executing behind the scene.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

        At least given the above context of calling ->ymd as a method, I wonder what code would have worked before but now not work due to not having parentheses. To me this interpretation looks as if there is a case where:

        $myobject->ymd;

        stops working but

        $myobject->ymd();

        continues to work, or maybe:

        $myobject->ymd $foo;

        stops working but

        $myobject->ymd($foo);

        continues to work.

        At least in my trials, I can't get the version without parentheses to even compile:

        > perl -wle "$myobject = bless {}; $myobject->ymd $foo" Scalar found where operator expected at -e line 1, near "->ymd $foo"

        Of course, it could be use of indirect object syntax such that the method ymd was changed to parse differently, but that's also something that would be hard to elicit the stated error message from.

        I think most (if not all) cases when you get

        Can't locate object method "ymd" via package "123456"

        ... the cause is that you tried to treat an unblessed value like an object and the value was not a class name.