<GEN5> ?

C

cmb99

I couldn't find the answer to this on the web, but when I get an error
like:

Modification of a read-only value attempted at
C:\dev\perl\script\mail.pl line 55, <GEN5> line 1908. It's a little
confusing. My script is called mail.pl, but I don't have 1900 lines in
it. I'm not really looking for help on the specific error, just what is
meant by output like this.
 
M

Mark Clements

I couldn't find the answer to this on the web, but when I get an error
like:

Modification of a read-only value attempted at
C:\dev\perl\script\mail.pl line 55, <GEN5> line 1908. It's a little
confusing. My script is called mail.pl, but I don't have 1900 lines in
it. I'm not really looking for help on the specific error, just what is
meant by output like this.
You have an open filehandle called GEN5. The error has been caused at
line 55 of your script while line 1908 has just been read from GEN5.

(from perldoc perldiag)

Modification of a read-only value attempted
(F) You tried, directly or indirectly, to change the value of a
constant. You didn't, of course, try "2 = 1", because the compiler
catches that. But an easy way to do the same thing is:

sub mod { $_[0] = 1 }
mod(2);

Another way is to assign to a substr() that's off the end of the
string.

Yet another way is to assign to a "foreach" loop *VAR* when *VAR* is
aliased to a constant in the look *LIST*:

$x = 1;
foreach my $n ($x, 2) {
$n *= 2; # modifies the $x, but fails on attempt to modify the 2
}

Mark
 
C

cmb99

Except that there aren't 1900 lines in the (imported) file either. Kind
of throwing my hands up in the air. This script works on exchange (MS)
inboxes but not on a pop3 server on the included component of win2k3
server.

Script attempts to read each e-mail, save attachments, and unzip saved
files:

#!/usr/bin/perl

use Mail::pOP3Client;
use Mail::MboxParser::Mail;
use Archive::Extract;

#connect to POP
$pop = new Mail::pOP3Client( USER => "username",
PASSWORD => "password",
HOST => "XXX.XXX.XXX.XXX",
PORT => 110,
DEBUG => 0,
AUTH_MODE => "PASS" );

$pop->Connect() || die $pop->Message();
print $pop->Count(), " message(s) in Inbox\n";

for( $i = 1; $i <= $pop->Count(); $i++ ) {
my @header = $pop->Head($i);
my @body = $pop->Body($i);
my $mail = new Mail::MboxParser::Mail (\@header, \@body) ;
my $numAttach = $mail->num_entities;
next if ($numAttach lt 1); # no attachments. body considered
attachment
my $mapping = $mail->get_attachments;
for my $filename (keys %$mapping) { # loop over attachments
next if $filename !~ /.*connectivity.*gzip/; # only interested in
connectivity logs
my $gz_filename = $filename;
$gz_filename =~ s/gzip/gz/;
#line that dies when connecting to MS pop3 vvvv
$mail->store_attachment($mapping->{$filename}, path => "temp") || die
("Died saving ", $filename, "\n", $mail->error()); # save to 'temp'
directory
rename "temp/".$filename, "temp/".$gz_filename; # Archive::Extract
doesn't understand gzip, only gz
$ae = Archive::Extract->new(archive => "temp/".$gz_filename, type=>
"gz");
$ae->extract(to => "temp");

# process xml

# write to database

}
}
}

$pop->Close();

Mark said:
I couldn't find the answer to this on the web, but when I get an error
like:

Modification of a read-only value attempted at
C:\dev\perl\script\mail.pl line 55, <GEN5> line 1908. It's a little
confusing. My script is called mail.pl, but I don't have 1900 lines in
it. I'm not really looking for help on the specific error, just what is
meant by output like this.
You have an open filehandle called GEN5. The error has been caused at
line 55 of your script while line 1908 has just been read from GEN5.

(from perldoc perldiag)

Modification of a read-only value attempted
(F) You tried, directly or indirectly, to change the value of a
constant. You didn't, of course, try "2 = 1", because the compiler
catches that. But an easy way to do the same thing is:

sub mod { $_[0] = 1 }
mod(2);

Another way is to assign to a substr() that's off the end of the
string.

Yet another way is to assign to a "foreach" loop *VAR* when *VAR* is
aliased to a constant in the look *LIST*:

$x = 1;
foreach my $n ($x, 2) {
$n *= 2; # modifies the $x, but fails on attempt to modify the 2
}

Mark
 
C

cmb99

Nevermind, had slashes in the attachment filenames.

Except that there aren't 1900 lines in the (imported) file either. Kind
of throwing my hands up in the air. This script works on exchange (MS)
inboxes but not on a pop3 server on the included component of win2k3
server.

Script attempts to read each e-mail, save attachments, and unzip saved
files:

#!/usr/bin/perl

use Mail::pOP3Client;
use Mail::MboxParser::Mail;
use Archive::Extract;

#connect to POP
$pop = new Mail::pOP3Client( USER => "username",
PASSWORD => "password",
HOST => "XXX.XXX.XXX.XXX",
PORT => 110,
DEBUG => 0,
AUTH_MODE => "PASS" );

$pop->Connect() || die $pop->Message();
print $pop->Count(), " message(s) in Inbox\n";

for( $i = 1; $i <= $pop->Count(); $i++ ) {
my @header = $pop->Head($i);
my @body = $pop->Body($i);
my $mail = new Mail::MboxParser::Mail (\@header, \@body) ;
my $numAttach = $mail->num_entities;
next if ($numAttach lt 1); # no attachments. body considered
attachment
my $mapping = $mail->get_attachments;
for my $filename (keys %$mapping) { # loop over attachments
next if $filename !~ /.*connectivity.*gzip/; # only interested in
connectivity logs
my $gz_filename = $filename;
$gz_filename =~ s/gzip/gz/;
#line that dies when connecting to MS pop3 vvvv
$mail->store_attachment($mapping->{$filename}, path => "temp") || die
("Died saving ", $filename, "\n", $mail->error()); # save to 'temp'
directory
rename "temp/".$filename, "temp/".$gz_filename; # Archive::Extract
doesn't understand gzip, only gz
$ae = Archive::Extract->new(archive => "temp/".$gz_filename, type=>
"gz");
$ae->extract(to => "temp");

# process xml

# write to database

}
}
}

$pop->Close();

Mark said:
I couldn't find the answer to this on the web, but when I get an error
like:

Modification of a read-only value attempted at
C:\dev\perl\script\mail.pl line 55, <GEN5> line 1908. It's a little
confusing. My script is called mail.pl, but I don't have 1900 lines in
it. I'm not really looking for help on the specific error, just what is
meant by output like this.
You have an open filehandle called GEN5. The error has been caused at
line 55 of your script while line 1908 has just been read from GEN5.

(from perldoc perldiag)

Modification of a read-only value attempted
(F) You tried, directly or indirectly, to change the value of a
constant. You didn't, of course, try "2 = 1", because the compiler
catches that. But an easy way to do the same thing is:

sub mod { $_[0] = 1 }
mod(2);

Another way is to assign to a substr() that's off the end of the
string.

Yet another way is to assign to a "foreach" loop *VAR* when *VAR* is
aliased to a constant in the look *LIST*:

$x = 1;
foreach my $n ($x, 2) {
$n *= 2; # modifies the $x, but fails on attempt to modify the 2
}

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top