Can't locate object method error

P

pakalk

Thank you for responses to my first topic. Here is second one.

Code:

my $xmls = new XML::Simple;
my $xml = $xmls->parse_string( $validXmlString );

Problem:

At localhost everything works. At server I get

Can't locate object method "parse_string" via package "XML::Simple"

error message. When I call

print $xmls;

i get

XML::Simple=HASH(0x1d32d8c)

XML::Simple has parse_string subroutine. What can be wrong? Do you
need more information?
 
J

J. Gleixner

pakalk said:
Thank you for responses to my first topic. Here is second one.

Code:

Although it doesn't really help, in this case, always
post code that actually runs.

use XML::Simple;
use strict;

my $validXmlString = '<?xml version="1.0"
encoding="UTF-8"?> said:
my $xmls = new XML::Simple;
my $xml = $xmls->parse_string( $validXmlString );

Problem:

At localhost everything works. At server I get

Can't locate object method "parse_string" via package "XML::Simple"

error message. When I call

print $xmls;

i get

XML::Simple=HASH(0x1d32d8c)

Of course you'd get that output. Not very helpful.

use Data::Dumper;
print Dumper( $xmls );
XML::Simple has parse_string subroutine.

Are you sure?
What can be wrong? Do you need more information?

It means it can't locate the method 'parse_string' in the package
XML::Simple.

What version of XML::Simple is on the 'server'?

Looks like that method was added in version 2.17:

2.17 Aug 02 2007
- Added parse_string(), parse_file() and parse_fh() methods
 
D

Dr.Ruud

Ben said:
pakalk:

This is considered bad style nowadays, and the form you are using (with
no arguments and no :: after XML::Simple) is definitely ambiguous. Use

my $xmls = XML::Simple->new;

instead.

Or even XML::Simple::->new;


perl -wle'
sub new { print __PACKAGE__."::new" }
{ package XML; sub Simple { print __PACKAGE__."::Simple()";
"XML::Simple" } }

{ package XML::Simple; sub new { print __PACKAGE__."::new()" } }

print 1;
my $x1 = new XML::Simple;

print 2;
my $x2 = XML::Simple->new;

print 3;
my $x3 = XML::Simple::->new;
'

1
XML::Simple()
main::new

2
XML::Simple()
XML::Simple::new()

3
XML::Simple::new()
 

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,999
Messages
2,570,246
Members
46,843
Latest member
WizcraftEntertainmentAgen

Latest Threads

Top