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

Iam trying to parse a XML file using XML::Simple module. The code is done and it works fine as expected. But i just want to make sure that file while reading is opened in read-only mode. This is the snippet that iam using
my $parser=XML::Simple->new(); my $doc = $parser->XMLin("./config.xml",, ForceArray => qr{Resource} +, keyAttr=> { 'server', 'name',KeepRoot => 1 });
Please let me know how to open a XML file in read-only mode using XML::Simple. Thanks for all the Suggestions

Replies are listed 'Best First'.
Re: XML::Simple read only mode
by choroba (Cardinal) on Apr 21, 2015 at 14:55 UTC
    If you don't trust XML::Simple, open the file yourself and give the module just the string:
    open my $READ, '<', './config.xml' or die $!; my $parser = 'XML::Simple'->new; my $doc = $parser->XMLin(do { local $/; <$READ> }, ForceArray => qr/Re +source/, KeyAttr => { ser +ver => 'name' }, KeepRoot => 1); # + I fixed the options.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: XML::Simple read only mode
by Athanasius (Archbishop) on Apr 21, 2015 at 14:59 UTC

    Hello jagadish1982,

    Please note the following, from the XML::Simple documentation:

    STATUS OF THIS MODULE
    The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, XML::LibXML is highly recommended.
    The major problems with this module are the large number of options and the arbitrary ways in which these options interact — often with unexpected results.

    You may already know this; but I’ve posted it in case you weren’t aware that better options are available. See also Task::Kensho::XML.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: XML::Simple read only mode
by ikegami (Patriarch) on Apr 21, 2015 at 14:47 UTC

    Which parser do you use?

    When using XML::Parser to parse the file, XML::Simple uses open(my $xfh, '<', $filename), so the file handle only allows reading.

    Other parsers open the file themselves, so you'd have to check the parser being used. They surely open the file for reading as well.