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

I'm running in to some issues with the using the "XMLin" in my code writing. The code below

#!/usr/bin/perl use XML::Simple; my $opt = XMLin('foo.xml'); print $opt;

in the foo.xml there's just some random xml code but I created it for the site to cause the error I keep getting with other scripts I've got that use the XML::Simple commands. The error I get is

Undefined subroutine &main::XMLin called at first.pl line 3.

Now I've searched around for this error and found someone who have troubles with it on this site however the code

perl -we "use XML::Simple; print $INC{'XML/Simple.pm'}"

returns an error not a file. the error being
syntax error at -e line 1, at EOF
Execution of -e aborted due to compilation errors.

I've tried removing XML::simple, and reinstalling it, though CPAN and from the download link on the owners site using the make install. I've also tried to reinstall perl 5.10.0, I'm using a debian linux server. Please show me the error of my ways.

Replies are listed 'Best First'.
Re: XML::Simple Issues
by Corion (Patriarch) on Dec 29, 2010 at 18:43 UTC

    Your program works for me, so I'm not sure what went wrong during your installation, deinstallation and reinstallation of XML::Simple. If you are using the system Perl (as indicated by your hashbang line of /usr/bin/perl), then I strongly advise you to use your OS package manager (apt-get, or aptitude) to install the Debian package of the Perl module instead of going via CPAN. Likely, the following will install the appropriate Debian package:

    apt-get install libxml-simple-perl

      I tried to install apt-get install libxml-simple-perl after it installed i tried to run the code again. perl -we use XML::Simple; print $INC{'XML/Simple.pm'} and I get the error still below

      syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors. Warning: unknown mime-type for "{XML/Simple.pm}" -- using "application +/octet-stream" Error: no such file "{XML/Simple.pm}"
        $ perl -e use syntax error at -e line 1, at EOF Execution of -e aborted due to compilation errors.
        See perlrun

        Alternatively, make a file

        $ cat junk87.pl use XML::Simple; print $INC{'XML/Simple.pm'} $ perl junk87.pl C:/perl/site/5.10.1/lib/XML/Simple.pm
Re: XML::Simple Issues
by codeacrobat (Chaplain) on Dec 29, 2010 at 21:47 UTC
    In *nix environments use single quotes to enclose the one-liner.
    perl -MXML::Simple -le 'print for %INC'

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
Re: XML::Simple Issues
by isotope (Deacon) on Dec 29, 2010 at 19:44 UTC
    In your diagnostic one-liner, your double-quotes leave $INC to be shell-interpreted. Escape it:
    perl -we "use XML::Simple; print \$INC{'XML/Simple.pm'}"


    --isotope

      Depends on the OS. Under Windows it would be all right without the backslashes.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

        That's fine, but the error he received is because on the Linux system he's using, he does need to escape the $.


        --isotope
      I removed the double quotes and I get

      syntax error at -e line 1, at EOF
      Execution of -e aborted due to compilation errors.
      Warning: unknown mime-type for "{XML/Simple.pm}" --
      using "application/octet-stream"
      Error: no such file "{XML/Simple.pm}"

        Not to get further bogged down in this issue that's really secondary to your question, but you still need quotes; you just didn't go quite far enough and asked the shell to interpret $ENV instead of passing it to perl.

        codeacrobat's one-liner is better anyway.


        --isotope