<?xml version="1.0"?> <!-- This is XML for the Notify Mapping --> <map> <CI name="ABC"> <recipient id="Usr-One"> <alert method="SMS" dest="+44123456789" st="" et=""> <enable>Y</enable> </alert> <alert method="EMAIL" dest="usr-one@nowhere.co.uk" st="" e +t=""> <enable>Y</enable> </alert> </recipient> <recipient id="User-two"> <alert method="SMS" dest="+44987654321" st="" et=""> <enable>Y</enable> </alert> <alert method="EMAIL" dest="user-two@anywhere.co.uk" st="" + et=""> <enable>Y</enable> </alert> </recipient> </CI> <CI name="DEF"> <recipient id="Usr-One"> <alert method="SMS" dest="+44123456789" st="" et=""> <enable>Y</enable> </alert> </recipient> </CI> </map>
use strict; use warnings; use XML::Simple; #use Data::Dumper; # I put this here to see what the hash looks like my $check = "ABC"; my $alert_config_file = "C:/Path to XML/AlertCIMap.xml"; my $XMLSimple = XML::Simple->new(forcearray => 1, keyattr => {}); eval { $rules = $XMLSimple->XMLin("$alert_config_file")}; if ($@) { print "Problems Reading $alert_config_file: $@\n"; exit; } #print Dumper($rules); if (&CI_Exists($check)) { print "Matched\n"; } else { print "NOT FOUND\n"; } ## SUB ROUTINES ## sub CI_Exists #Check if CI exists in Mapping { my $chk = shift; my $rc = 0; #Foreach name in xml look for match my $ci = $rules->{CI}; foreach my $n(@$ci) { if ($n->{name} eq $chk){ print "Chk = $chk\n"; #Just for testing so I can s +ee stuff is happening #THIS NEXT LINE IS CAUSING ME FRUSTRATION... my $rec_list = $n->{name}->{recipients}; #List of +Recepients foreach my $recipient(@$rec_list) { #foreach Alert create file. print "Recipient = $recipient\n"; my $alert_list = # What should go here +..?? List of Alerts foreach my $alert($alert_list){ print"I Would Send a $alert to $recipient\n"; } } $rc = 1; last; } } return($rc); }
In reply to XML::Simple and arrays by J9
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |