Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: "Text" does something.

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


in reply to "Text" does something.

CPAN.pm 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


Comment on Re: "Text" does something.
Select or Download Code
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 CPAN.pm 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.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024991]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-10-31 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (214 votes), past polls