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

Hi, I don't know why I am getting this error, because just a few days ago this was working fine, and I have correctly installed the XML::Simple package. I have the following line at around 10 lines down, at the beginning of my script:

use XML::Simple;

Then, later on in the script, in using the XMLin() function, I have the following lines:

$outxml = `c:\\WINNT\\system32\\cscript c:\\buildscript\\soapcall.js $serverName "$reqxml" "0"`;
$outxml =~ /(\<HelloWorld.*\<\/HelloWorld\>)/; #extracting the xml output returned by the soap call
$outxmlParsed = XMLin($1);


Whenever I try to run it though, I get the following error:

Undefined subroutine &main::XMLin called at c:\buildscript\ScriptFile.pl line 69.

Does anyone know why I am getting this error?

Responses greatly appreciated,

Brent.
  • Comment on Using the XMLin() method in XML::Simple not working

Replies are listed 'Best First'.
Re: Using the XMLin() method in XML::Simple not working
by cees (Curate) on May 31, 2005 at 18:49 UTC

    Is that the exact code, or are you writing from memory? It looks like it should work. The error message you received tells you that the XMLin function was not imported into your namespace.

    Are you perhaps loading XML::Simple like this:

    use XML::Simple ();

    The () tell perl to not import any symbols when loading the module. The easiest way to see if this is your problem is to fully qualify the call to XMLin (which makes your code a lot clearer as well IMO)

    $outxmlParsed = XML::Simple::XMLin($1);
      Hi, thank you for your response.

      I pasted those lines of code in from my script, so that is syntactically how I am loading the package and making the call to XMLin.

      I tried your suggestion of XML::Simple::XMLin($1); but that still didn't work, as this time I get the error:

      Undefined subroutine &XML::Simple::XMLin called at c:\buildscript\Clues1TestScript.pl line 69.

      Any other ideas?

        It's as if the use was never executed, the use failed but the exception was caught, or if it's not loading the module it should load.

        What does
        perl -we "use XML::Simple; print $INC{'XML/Simple.pm'}"
        give you? A warning or a file name?

        If it returns the a file name, can you give us the first 20-50 lines of that file? What follows is the top lines from the newest version, but even as far back 1.06 is very similar

        >perl -we "use XML::Simple; print $INC{'XML/Simple.pm'}" r:/Utils/perl/site/lib/XML/Simple.pm >type "r:\Utils\perl\site\lib\XML\Simple.pm" # $Id: Simple.pm,v 1.23 2005/01/29 04:16:10 grantm Exp $ package XML::Simple; =head1 NAME XML::Simple - Easy API to maintain XML (esp config files) =head1 SYNOPSIS use XML::Simple; my $ref = XMLin([<xml file or string>] [, <options>]); my $xml = XMLout($hashref [, <options>]); Or the object oriented way: require XML::Simple; my $xs = new XML::Simple(options); my $ref = $xs->XMLin([<xml file or string>] [, <options>]); my $xml = $xs->XMLout($hashref [, <options>]); (or see L<"SAX SUPPORT"> for 'the SAX way'). To catch common errors: use XML::Simple qw(:strict); (see L<"STRICT MODE"> for more details). =cut # See after __END__ for more POD documentation # Load essentials here, other modules loaded on demand later use strict; use Carp; require Exporter; ###################################################################### +######## # Define some constants # use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $PREFERRED_PARSER); @ISA = qw(Exporter); @EXPORT = qw(XMLin XMLout); @EXPORT_OK = qw(xml_in xml_out); $VERSION = '2.14'; $PREFERRED_PARSER = undef;

        You are going to have to create a small script that recreates this problem. Remove everything from the script that does not have anything to do with XML::Simple.

        Most likely during that exercise you will notice that you have found/fixed the problem yourself. If not, then show us that script and we should be able to help. Right now you haven't given us enough info to know exactly what is wrong, so we are left to guess.

Re: Using the XMLin() method in XML::Simple not working
by ikegami (Patriarch) on May 31, 2005 at 19:49 UTC

    Did you put the use in a different package? What the use identical to what you posted, or did it have a list (empty or otherwise)? Did you use require (which doesn't import) instead of use?

    #!/usr/bin/perl use XML::Simple (); BEGIN { print(__PACKAGE__->can('XMLin') ? 1 : 0, "\n"); } # 0 use XML::Simple; BEGIN { print(__PACKAGE__->can('XMLin') ? 1 : 0, "\n"); } # 1 package Other; BEGIN { print(__PACKAGE__->can('XMLin') ? 1 : 0, "\n"); } # 0 use XML::Simple; BEGIN { print(__PACKAGE__->can('XMLin') ? 1 : 0, "\n"); } # 1 package YetOther; BEGIN { print(__PACKAGE__->can('XMLin') ? 1 : 0, "\n"); } # 0 use XML::Simple qw( XMLout ); BEGIN { print(__PACKAGE__->can('XMLin') ? 1 : 0, "\n"); } # 0 use XML::Simple qw( XMLin ); BEGIN { print(__PACKAGE__->can('XMLin') ? 1 : 0, "\n"); } # 1 package main; # Back to first package. BEGIN { print(__PACKAGE__->can('XMLin') ? 1 : 0, "\n"); } # 1
      Hi, I didn't use the package, or require keywords anywhere. The use statement really was identical to what I posted, which was just copied and pasted from the script.