http://www.perlmonks.org?node_id=569882

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

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.