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

I'm moving from cpan to cpanplus to install modules because sometimes I need to for specific versions. While:
cpanp -i Compress-Zlib-1.42
works, I need to use it via
perl -MCPANPLUS -e "..."
I've gotten:
perl -MCPANPLUS -e "install(Compress::Zlib)"
to work, for example, but I've been unable to get anything with versions involved to also work.
[build@build ~]$ perl -MCPANPLUS -e "install(Compress-Zlib-1.42)"
ERROR No such module '-1.42'
[build@build ~]$ perl -MCPANPLUS -e "install(Compress-Zlib)"
ERROR No module specified!

According to the documentation, specifying the author path should work:
[build@build ~]$ perl -MCPANPLUS -e 'install(/P/PM/PMQS/Compress-Zlib- +1.42)'
Bareword found where operator expected at -e line 1, near "/P/PM" (Missing operator before PM?)

Anyone know how I can do this? Thanks!

Replies are listed 'Best First'.
Re: CPANPLUS with versioned Modules
by ysth (Canon) on Jun 20, 2007 at 02:19 UTC
    You need to quote the module or distribution names. Also, you seem to be missing a -w switch :)
    ysth@raven:~$ perl -wle'sub i { print "installing: $_[0]" } i(Compress +::Zlib)' installing: Compress::Zlib ysth@raven:~$ perl -wle'sub i { print "installing: $_[0]" } i(Compress +-Zlib-1.42)' Argument "Zlib" isn't numeric in subtraction (-) at -e line 1. Argument "Compress" isn't numeric in subtraction (-) at -e line 1. installing: -1.42 ysth@raven:~$ perl -wle'sub i { print "installing: $_[0]" } i(Compress +-Zlib)' Argument "Zlib" isn't numeric in subtraction (-) at -e line 1. Argument "Compress" isn't numeric in subtraction (-) at -e line 1. installing: 0
      Quoting the module doesn't fix my underlying issue, which is being able to specify a version. It does fix the problem with -1.42 being called a module.
      perl -MCPANPLUS -e 'install("/P/PM/PMQS/Compress-Zlib-1.42")' [ERROR] No such module '/P/PM/PMQS/Compress-Zlib-1.42'
      perl -MCPANPLUS -e 'install("Compress-Zlib-1.42")' [ERROR] No such module 'Compress-Zlib-1.42'
      Help still desired. :)
        Going by the documentation, it looks like you need to add the extension:
        perl -MCPANPLUS -we 'install("/P/PM/PMQS/Compress-Zlib-1.42.tar.gz")'
        but I just looked at the code, and there doesn't actually seem to be support for this at all. I suggest you file a bug.
Re: CPANPLUS with versioned Modules
by Roy Johnson (Monsignor) on Jun 20, 2007 at 17:27 UTC
    Put the fully qualified path in quotes:
    perl -MCPANPLUS -e 'install("/P/PM/PMQS/Compress-Zlib-1.42")'

    Caution: Contents may have been coded under pressure.
      [root@build .cpanplus]# perl -MCPANPLUS -e 'install("/P/PM/PMQS/Compre +ss-Zlib-1.42")' [ERROR] No such module '/P/PM/PMQS/Compress-Zlib-1.42'
      Still doesn't work.
      perl -MCPANPLUS -e 'install("Compress::Zlib")'
      continues to work, but gets the latest version which I need to avoid.
        Corion found it can be done with CPAN at least:
        perl -MCPAN -e "install(qq(P/PM/PMQS/Compress-Zlib-1.42.tar.gz))"
        Thanks!