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

Guys, Here is my code :

use strict; use warnings; use Data::Dumper; use XML::Simple; $/=undef; open ('handle', "/home/cpos/aznapi_webseald-default.log") or die ("can +not open file : $!"); my $xml = <handle>; my $ref = XMLin $xml; print Dumper $ref; close "handle";

Want to read the XML file "aznapi_webseald-default.log" and convert it.

Please help

Replies are listed 'Best First'.
Re: XML log file to readable format conversion
by toolic (Bishop) on Jan 15, 2014 at 14:59 UTC
    There should be no need to open a file before reading it in with XMLIn. Just pass the file to XMLIn:
    use strict; use warnings; use Data::Dumper; use XML::Simple; my $ref = XMLin('/home/cpos/aznapi_webseald-default.log$xml'); print Dumper $ref;

    See also:

    • XML::Simple
    • STATUS OF THIS MODULE: "The use of this module in new code is discouraged."

    UPDATE: Fixed typo in my untested code (remove $xml):

    use strict; use warnings; use Data::Dumper; use XML::Simple; my $ref = XMLin('/home/cpos/aznapi_webseald-default.log'); print Dumper $ref;

      I am getting following error :

      Only Comments, PIs and whitespace allowed at end of document Ln: 15, Col: 1

        Your input file is not a well-formed XML. It probably contains some additional information after the closing root tag.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        I had a typo in my untested code example. Refer to my update.