GerryD has asked for the wisdom of the Perl Monks concerning the following question:
As you can see, I need to write the $device_name and $port_name in the single filter, the way it does currently do it (as above) it will do a foreach and try to write the filter xml each time, but as it can only exist once it will end up with a single filter with single device and port. trying to put the foreach inbetween the middle of the xml writer statement, it will return an error. the end result should end in (where node='node1" and port=port1) or (where node='node2" and port=port2) so whether there are 100 nodes and ports or 1000's it must write in that sequence in a single filter. i hope this made sense.use IO::File; use XML::Writer; my $output = IO::File->new(">wheretowrite.xml"); my $writer = XML::Writer->new(OUTPUT => $output); my @device_list = ( "node1 port1" , "node2 port2" , "node3 port3" ) foreach $node(@device_list) { @get_data = split ( ' ' , $node ); $device_name = @get_data[0]; $port_name = @get_data[1]; $writer->startTag("filter", "name" => "all_events", "sql" => "(where + node ="$device_name and port=$port_name") or (where node="device_nam +e and port=$port_name"), "label" => "just-testing", "view" => "Defaul +t"); $writer->endTag( "filter" ); } # end
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: xml::Writer query
by McA (Priest) on Oct 15, 2012 at 09:05 UTC | |
by GerryD (Initiate) on Oct 16, 2012 at 07:57 UTC |