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

I wanted to "inline" an XML template into a simple script, but I'm banging my head against the desk trying to dereference the ioref to the inline DATA. Any widsom you'd care to share will be greatly appreciated!
#!/usr/loca/bin/perl use warnings; use strict; use Data::Dumper; use XML::Simple; my $xs = new XML::Simple(); # Instantiate new XML Parser my $template = $xs->XMLin( *DATA ); # Parse inline XML file print Dumper $template; exit; __DATA__ <?xml version='1.0' standalone='yes'?> <RULE output_format="pdf" lsog_version="lsog5"> <SERVICE_REQUEST> <SOMETAG min_length="25" max_length="60">Some value</SOMETAG> <ANOTHER_TAG min_length="0" max_length="8">another value</ANOTHER_ +TAG> </SERVICE_REQUEST> </RULE>

Replies are listed 'Best First'.
Re: Inline XML
by mirod (Canon) on May 02, 2005 at 17:31 UTC

    Indeed you need to pass a reference to DATA: \*DATA:

    my $template = $xs->XMLin( \*DATA );  # Parse inline XML file
Re: Inline XML
by jZed (Prior) on May 02, 2005 at 17:34 UTC
    \*DATA
Re: Inline XML
by davidrw (Prior) on May 02, 2005 at 17:59 UTC
    The __DATA__ method seems to definitely be the right way here (w/purely static string data), but it in the interest of plugging a module i find handy (and preparing for more complicated scenarios, keep in mind something like this should work as well, using IO::Scalar:
    my $data = <<EOF; <?xml version='1.0' standalone='yes'?> <RULE output_format="pdf" lsog_version="lsog5"> <SERVICE_REQUEST> <SOMETAG min_length="25" max_length="60">Some value</SOMETAG> <ANOTHER_TAG min_length="0" max_length="8">another value</ANOTHER_ +TAG> </SERVICE_REQUEST> </RULE> EOF use IO::Scalar; my $SH = new IO::Scalar \$data; my $template = $xs->XMLin( $SH );
Re: Inline XML
by heathen (Acolyte) on May 02, 2005 at 19:41 UTC
    Thanks for quick reply all - \*DATA is exactly what I needed!