Can't locate object method error

Discussion in 'Perl Misc' started by pakalk, Mar 27, 2009.

  1. pakalk

    pakalk Guest

    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?
     
    pakalk, Mar 27, 2009
    #1
    1. Advertisements

  2. pakalk

    J. Gleixner Guest

    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"
    Of course you'd get that output. Not very helpful.

    use Data::Dumper;
    print Dumper( $xmls );
    Are you sure?
    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
     
    J. Gleixner, Mar 27, 2009
    #2
    1. Advertisements

  3. pakalk

    Dr.Ruud Guest

    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()
     
    Dr.Ruud, Mar 27, 2009
    #3
  4. pakalk

    pakalk Guest

    Thanks for all responses.

    I will try to use them :)
     
    pakalk, Mar 30, 2009
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.