Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Unitialized value and splice offset in RTF::Document

by inblosam (Monk)
on Sep 01, 2004 at 04:13 UTC ( [id://387395]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to make RTF's using RTF::Document. It's not bad, just had a bunch of flags come up. I can still have it generate a file on my computer, but on my server inside my application it won't run due to these same flags (I'm using Mason). So I am trying to edit the module on my server to get rid of the problems. Only 2 left...but I can't figure out how to do it. Any suggestions? Here is the error: Use of uninitialized value in concatenation (.) or string at /usr/local/lib/perl5/site_perl/5.8.0/RTF/Document.pm line 472. splice() offset past end of array at /usr/local/lib/perl5/site_perl/5.8.0/RTF/Document.pm line 805. And here are the lines of code around those numbers...
sub import { my $self = shift; $self->set_properties (\%DOCINFO, @_); ## here comes 472 ## $self->splice_raw ($self->{DOCUMENT}, 1, 1, "\\".$self->{charset}); # --- Insert creation time in Information Group if ($self->{creatim}) { my ($ss, $mn, $hr, $dd, $mm, $yy) = localtime($self->{creatim} +); $yy+=1900; $mm++; my $creatim = $self->add_group($self->{info}); $self->add_raw( $creatim, '\creatim', "\\yr$yy", "\\mo$mm", "\\dy$dd", "\\hr$hr", "\\min$mn", "\ +\sec$ss" ); $self->{creatim} = 0; }; }
Here's the code around line 805.
sub splice_raw # splice a raw value into a section { my $self = shift; my $section = shift; my $position = shift; my $length = shift; ## here comes 805 ## splice @{$section}, $position, $length, @_; }
Any help or suggestions are appreciated!

Replies are listed 'Best First'.
Re: Unitialized value and splice offset in RTF::Document
by tachyon (Chancellor) on Sep 01, 2004 at 08:06 UTC

    Your first issue is that $self->{charset} is undefined as this is the only concatenation happening. The real issue is why it is undefined? The splice warning indicates that $self->{DOCUMENT} is either undef or a zero element array.

    The problem is the name of the import() sub itself. When you use a module Perl will call that modules import() function if it exists or Exporter's import() function if Exporter is in use (Exporter is uselessly used in this module BTW)

    In the new function() we can see:

    $self->initialize(); $self->import(@_);

    This is fine as initialize() will define {charset} and {DOCUMENT}, before the call to import(). The issue is that import() is called immediately you use RTF::Document, so it gets called before you call new. You can fix the problem with a simple s/import/important_not_to_call_stuff_import/g or similar.

    As an asside this module has not been touched since 2000 so is probably abandonware. If you have an interest it might be worth taking over maintenance. There are also modules like RTF::Writer that seem better maintained. If you do take over maintenance then please delete these redundant lines at the top of the module:

    require Exporter; .... @ISA = qw(Exporter); @EXPORT = qw(); @EXPORT_OK = qw();

    cheers

    tachyon

      I did see RTF::Writer but I created some code that working a few months back...so I was trying to spare redoing that. But, RTF::Writer (after trying it) is a bit easier and no errors! Thanks for the tips, I will use RTF::Writer instead of the abandonware. -Michael
Re: Unitialized value and splice offset in RTF::Document
by rrwo (Friar) on Nov 23, 2004 at 18:38 UTC

    FYI, RTF::Document is no longer supported by the author. (In fact, maintenance of the module is up for graps if anyone wants to take it over.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://387395]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-29 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found