Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: "Text" does something.

by NetWallah (Canon)
on Mar 22, 2013 at 23:08 UTC ( #1024991=note: print w/replies, xml ) Need Help??

in reply to "Text" does something. includes the statement:
use Text::ParseWords ();
It looks like the perl interpreter notices the existence of the namespace, and decides to invoke "install" as a method of that namespace.

Changing the spelling of the module slightly modifies the way perl parses it.

I don't know why.

I see the same effect when trying to "install" File::Basename or other "File::" modules used by CPAN.

C:\Perl64\lib>perl -MO=Deparse -MCPAN -e "install File::Basename" Set up gcc environment - gcc.exe (rubenvb-4.5.4) 4.5.4 use CPAN; 'File::Basename'->install; # Method call (unexpected) -e syntax OK -- change the name ----- C:\Perl64\lib>perl -MO=Deparse -MCPAN -e "install File::BasenameXXX" Set up gcc environment - gcc.exe (rubenvb-4.5.4) 4.5.4 use CPAN; install('File::BasenameXXX'); ## What we expect -e syntax OK

             "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
        -- Dr. Cox, Scrubs

Replies are listed 'Best First'.
Re^2: "Text" does something.
by Jenda (Abbot) on Mar 24, 2013 at 02:03 UTC

    If there already is a package Foo in the running program, then "whatever Foo;" is assumed to mean call to static method whatever() in package Foo. If it's not and use strict is not in effect, the "Foo" is considered a bareword and the subroutine import() in current package is called and the string "Foo" is passed as the first parameter. In this particular case the module File::Basename is loaded by or one of its dependencies, so Perl assumes you meant the first meaning.

    It's preferable to use Foo->import() is you mean the static method call and import("Foo") if you mean the subroutine call.

    Enoch was right!
    Enjoy the last years of Rome.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024991]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2018-03-22 14:06 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (276 votes). Check out past polls.