CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Error when creating a new instance of XML::Writer

 



ev0lution37
Novice

Nov 8, 2012, 11:28 AM

Post #1 of 7 (2211 views)
Error when creating a new instance of XML::Writer Can't Post

I'm trying to implement XML::Writer to help dump a MySQL database to XML format, however I'm getting the following error:


Quote
Can't locate object method "new" via package "XML::Writer" at /apollo/volume/software/application/artemis/bin/KapowStarter.pl line 371.


I'm implementing the code as a subroutine, but when I initially had it running locally as it's own script it was functioning just file.

Here's the spot of code that is giving me the problems. It seems that it is trying to find the 'new()' function within the XML::Writer module, but can't find it. No clue why not. Thanks in advance for the help!


Code
sub SQLtoXML { 

$log->debug("Attempting to pull from MySQL DB and write to XML.." . "\n");

#Parameter being passed is the Source ID to check against the Database and final directory for XML file.
my $PassedSource = $_[0];
my $FinalDir = $_[1];

my $FileName = "";

#Set up temporary XML output file for XML::Writer
my $output = IO::File->new(">output.xml");

#Initiate XML::Writer
my $writer = XML::Writer->new(OUTPUT => $output);



FishMonger
Veteran / Moderator

Nov 8, 2012, 11:32 AM

Post #2 of 7 (2210 views)
Re: [ev0lution37] Error when creating a new instance of XML::Writer [In reply to] Can't Post

Did you forget to load the module, i.e., are you missing this:

Code
use XML::Writer;



ev0lution37
Novice

Nov 8, 2012, 11:56 AM

Post #3 of 7 (2208 views)
Re: [FishMonger] Error when creating a new instance of XML::Writer [In reply to] Can't Post

Thanks for the reply. It is loaded at the top of the script, and the Module uploaded to the appropriate place.


FishMonger
Veteran / Moderator

Nov 8, 2012, 12:17 PM

Post #4 of 7 (2202 views)
Re: [ev0lution37] Error when creating a new instance of XML::Writer [In reply to] Can't Post

The error you're receiving will occur if the module isn't loaded.

You might want to take a closer look at your script and verify that the module is actually loaded and not commented out.

What version of perl and the module are you using?


ev0lution37
Novice

Nov 8, 2012, 12:31 PM

Post #5 of 7 (2199 views)
Re: [FishMonger] Error when creating a new instance of XML::Writer [In reply to] Can't Post

It's definitely being loaded at the top, no comments or anything.

I guess version issues could be it. The server I'm running on currently has Perl v5.8.8, and the module is v0.615.

Thanks again.


FishMonger
Veteran / Moderator

Nov 8, 2012, 12:40 PM

Post #6 of 7 (2197 views)
Re: [ev0lution37] Error when creating a new instance of XML::Writer [In reply to] Can't Post

The only way I can duplicate your issue is to not load the module.


Quote
[root@099-91-RKB01 ~]# cat test.pl
#!/usr/bin/perl

use strict;
use warnings;
use IO::File;
use XML::Writer;

#Set up temporary XML output file for XML::Writer
my $output = IO::File->new(">output.xml");

#Initiate XML::Writer
my $writer = XML::Writer->new(OUTPUT => $output);

[root@099-91-RKB01 ~]# ./test.pl
[root@099-91-RKB01 ~]# vim test.pl
[root@099-91-RKB01 ~]# cat test.pl
#!/usr/bin/perl

use strict;
use warnings;
use IO::File;
#use XML::Writer;

#Set up temporary XML output file for XML::Writer
my $output = IO::File->new(">output.xml");

#Initiate XML::Writer
my $writer = XML::Writer->new(OUTPUT => $output);

[root@099-91-RKB01 ~]# ./test.pl
Can't locate object method "new" via package "XML::Writer" (perhaps you forgot to load "XML::Writer"?) at ./test.pl line 12.


I'm using the same versions as you.

See if you get the same problem with that test script.


ev0lution37
Novice

Nov 13, 2012, 5:13 PM

Post #7 of 7 (2142 views)
Re: [FishMonger] Error when creating a new instance of XML::Writer [In reply to] Can't Post

My apologies for the long, drawn-out reply. I ended up getting side-tracked on another issue. Anyways, it looks like CPAN was for some reason installing the wrong module under the name XML::Writer. Just had to copy the write one to the proper location and it started working wonderful. Thanks again for the help!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives