use strict; use warnings; use CPAN; for ( 'Catalyst::Plugin::Authentication' ) { install ($_)} #doesn't wo +rk #for my $mod ( 'Catalyst::Plugin::Authentication' ) { install ($mod)} +#works
The error I get with the $_ variant happens at the write makefile step:
... blah blah blah... Removing previously used /home/thartman/.cpan/build/Catalyst-Plugin-Au +thentication-0.09 CPAN.pm: Going to build N/NU/NUFFIN/Catalyst-Plugin-Authentication-0 +.09.tar.gz Checking if your kit is complete... Looks good Writing Makefile for Catalyst::Plugin::Authentication Modification of a read-only value attempted at /home/thartman/perlroot +/perl/lib/5.8.8/CPAN.pm line 4676.

I don't understand why my $var works, but $_ from the loop doesn't. I thought $_ was automatically lexically scoped, and could be relied on to do the same thing as specifying my $var before the for list. What gives?

By the way, to test this, I had my perl root directory tarred up. Before running the script I reverted my perl root directory by

thartman@nbartertest:~/nbarter$ cat ~/perlroot-revert #!/bin/bash rm -rf perlroot tar -xzvf perlroot.tar.gz
Then I ran perl -e 'use Catalyst::Plugin::Authentication'

to confirm that this produced an error because of the missing module, and then I would run the script to see if things installed ok or not.

Also, there's nothing special about Catalyst::Plugin::Authentication. This error seems to be produced regardless of what module I try to install.

Blessings to the monastery.


In reply to cpan install($_) doesn't work in loop, but normal lexical var does by tphyahoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.