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

I have 500+ XML files to extract data from and am new to XML, so I was over the moon to find the excellent explanation of XML::Simple on CPAN. I've got the data into a hash ref and set to work on extracting the indevidual values only to find that the writers of the XML used '-' in the tags, resulting in PERL treating them as minus symbols. I think?

$xml_ref->{identifier}->{formal-parameter} #? formal 'minus' parameter.

Does anyone know a way round this or do I need more then XML::Simple

Thanks are due also to http://www.w3schools.com/xml/xml_elements.asp for it's excellent intro to XML.

Replies are listed 'Best First'.
Re: XML::Simple - Limitations
by itub (Priest) on May 20, 2004 at 14:23 UTC

    Have you tried quoting the names?

    $xml_ref->{'identifier'}->{'formal-parameter'}

    The autoquoting of hash keys only works for things that look like simple words (letters, numbers, underscores...).

      Thanks to all of you I had tried this earlier but had made a second error and in my ignorance blamed the XML and XML::Simple, when it was really, plain old simple me. I'm pleased to report the data is flowing like a stream now.

      Thanks again with the help of the monks and the fine folks at www.3c.org, I've achived a lot, in a very short time today. We are so lucky to have a community which is happy to share its knowledge.

Re: XML::Simple - Limitations
by mifflin (Curate) on May 20, 2004 at 14:26 UTC
    quote your hash keys...
    $xml_ref->{identifier}->{'formal-parameter'}
    in this condition.
Re: XML::Simple - Limitations
by mirod (Canon) on May 20, 2004 at 14:24 UTC
    $xml_ref->{identifier}->{'formal-parameter'} # OK