Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

"Text" does something.

by Anonymous Monk
on Mar 22, 2013 at 20:47 UTC ( #1024978=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

The word Text is doing something funny in my perl installation:
% perl-5.16/bin/perl -MCPAN -e 'install Text::ParseWords' Can't locate object method "install" via package "Text::ParseWords" at + -e line 1.
Installing any module that doesn't start with "Text::" works. If I quote the module, like this:
perl-5.16/bin/perl -MCPAN -e 'install "Text::ParseWords"'
it works fine. This is with perl-5.16.3, but I've seen it on many different versions.

Comment on "Text" does something.
Select or Download Code
Re: "Text" does something.
by toolic (Chancellor) on Mar 22, 2013 at 21:01 UTC
    Tip #6 from the Basic debugging checklist ... B::Deparse:
    % perl -MO=Deparse -MCPAN -e 'install Text::ParseWords' use CPAN; 'Text::ParseWords'->install; -e syntax OK % perl -MO=Deparse -MCPAN -e 'install "Text::ParseWords"' use CPAN; install('Text::ParseWords'); -e syntax OK

    Can you try this instead?

    % cpan Text::ParseWords
Re: "Text" does something.
by Khen1950fx (Canon) on Mar 22, 2013 at 21:36 UTC
    FWIW, the use of
    perl -MCPAN -e 'install "Text::ParseWords"'
    is more of a canonical tradition for CPAN documentation. In realtime, everyday life, I never use it and never have:). In addition, Text::ParseWords is a core, dual-lived module that has been core since the first release of perl5. You could update it individually, or you could update it collectively by running:
    cpan Task::DualLived
    All of the dual-lived modules will be updated for you.
Re: "Text" does something.
by NetWallah (Abbot) on Mar 22, 2013 at 23:08 UTC
    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

      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: perlquestion [id://1024978]
Approved by toolic
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-11-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls