nottux has asked for the wisdom of the Perl Monks concerning the following question:

perl -e 'eval "120*312-77728+2.22772.224792222->x"; print $@' Can't locate object method "x" via package "壴��& +#65533;���" (perhaps you forgot to load "&#2277 +2;������"?) at (eval 1) lin +e 1.
Does anyone know why this math expression suddenly turns into a weird multi-character package name?

Replies are listed 'Best First'.
Re: What's going on here?
by choroba (Cardinal) on Jul 13, 2023 at 09:02 UTC
    perl -MO=Deparse,-p -e '120*312-77728+2.22772.224792222->x' ((-40288) + "\cB\x{58f4}\x{d660e9e}"->x);

    Still asking why?

    2.22772.224792222 is not a number, it's "version" string, i.e. three characters whose ords are 2, 22772, and 224792222. The -> operator is called on this string which interprets it as a class name.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Good catch about the version string but I would only say The -> operator is called on this string which interprets it as a class name. It has nothing to do with version string, e.g. 42->x does the same. I think.

        Yes, 42 is turned into the string "42" which is interpreted as a class name. Basically, anything that's not a reference is stringified by the arrow operator.

        Update: See The Arrow Operator in perldoc.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: What's going on here?
by kcott (Archbishop) on Jul 13, 2023 at 08:59 UTC

    G'day nottux,

    Welcome to the Monastery.

    I don't know what you intended. I suspect you're missing characters or have incorrect characters. What you've actually got here is:

    1. 120*312-77728 -- an arithmetical expression
    2. + -- added to
    3. 2.22772.224792222 -- v-string (as a package name)
    4. -> -- calling method
    5. x -- x

    Take a look at "perldata: Version Strings"; noting "If there are two or more dots in the literal, the leading v may be omitted."

    — Ken

Re: What's going on here?
by hippo (Archbishop) on Jul 13, 2023 at 08:38 UTC

    Because by attempting to call a method on it you are treating it like a package name. What did you expect to happen?


    🦛