Advertisement

11.15.2007 at 07:22AM PST, ID: 22963033
[x]
Attachment Details

Modification of a read-only value attempted...

Asked by mjcoyne in Perl Programming Language

Tags: attempted, modification, perl

Hi Experts --

I've been looking at this too long -- I can't spot the (probably obvious) problem.  I'm hoping a fresh set of eyes will help.

Here is a stripped down version of a larger script.  The actual script has many more entries in the %species hash, does some stuff between the "foreach" loops, actually does some work on the downloaded files, etc., but this is sufficient to trigger the error:

"Modification of a read-only value attempted at C:\Documents and Settings\Mike\Desktop\bf gene data\test.pl line 31."

The FTP portion retrieves the files fine -- in fact, once I have them, I can comment out that entire piece and the error still occurs.

Note that the script does not die at opening the file (line 30), and that the "for" loop and construction of the $file name variable is the same for both the FTP and the "open file" sections, but the script only dies when it attempts to read the file; the FTP portion works as expected.

I've tried all the obvious stuff: the files are not read-only, are in fact there, and can be opened and read if named explictly.

#!/usr/bin/perl -w
use strict;
use Net::FTP;
use Cwd 'abs_path';

my %species = (
    'Bacteroides_fragilis_NCTC_9434' => 'CR626927',
    );

my $home = abs_path(".");
my $datapath = "$home/srRNA";

mkdir $datapath unless (-e $datapath);
chdir ($datapath) or die;

foreach my $organism (sort keys %species) {
    my $ftp = Net::FTP->new("ftp.ncbi.nih.gov", Debug => 0) or die "Cannot connect to ftp.ncbi.nih.gov: $@";
    $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message;
    $ftp->cwd("/genbank/genomes/Bacteria/$organism/") or die "Cannot change working directory ", $ftp->message;
    for ('.ptt', '.rnt') {
        my $file = $species{$organism} . $_;
        $ftp->get($file) or die "get $file failed ", $ftp->message;
    }
    $ftp->quit;
}

foreach my $organism (sort keys %species) {
    for ('.ptt', '.rnt') {
        my $file = $species{$organism} . $_;
        open (TAB, $file) or die "Can't open $file: $!\n";
        while (<TAB>) {
            next unless /^\d+\.\.\d+/;
        }
        close (TAB);
    }
}

Thanks for your help...Start Free Trial
 
Loading Advertisement...
 
[+][-]11.15.2007 at 08:59AM PST, ID: 20290467

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.15.2007 at 09:01AM PST, ID: 20290490

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.15.2007 at 10:55AM PST, ID: 20291352

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.15.2007 at 12:05PM PST, ID: 20291912

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Perl Programming Language
Tags: attempted, modification, perl
Sign Up Now!
Solution Provided By: Adam314
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11.15.2007 at 01:28PM PST, ID: 20292686

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.15.2007 at 02:24PM PST, ID: 20293105

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.15.2007 at 03:14PM PST, ID: 20293851

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.15.2007 at 08:33PM PST, ID: 20296023

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.16.2007 at 03:13AM PST, ID: 20297372

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628