<GEN5> ?

Discussion in 'Perl Misc' started by cmb99@operamail.com, Jan 22, 2007.

  1. Guest

    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.
     
    , Jan 22, 2007
    #1
    1. Advertising

  2. wrote:
    > 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
     
    Mark Clements, Jan 22, 2007
    #2
    1. Advertising

  3. Guest

    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 Clements wrote:
    > wrote:
    > > 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
     
    , Jan 22, 2007
    #3
  4. Guest

    Nevermind, had slashes in the attachment filenames.

    wrote:
    > 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 Clements wrote:
    > > wrote:
    > > > 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
     
    , Jan 22, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page