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

Hi, i used ForceArray to make sure my <server> element will can be an array. But i when i debug, i found its still an hash Experts help pls
##########Sample input####### <?xml version="1.0" ?> <!DOCTYPE config SYSTEM "fefm_config.dtd"> <config> <server name="example_only" active="true"> <nas_repository_unc>\\corp.dummy.com\d +ev\General_CIFS_Workspace\MobileTest\dev\nas_rep</nas_repository_unc> <nas_archive_unc>\\corp.dummy.com\dev\General_CIFS_Wor +kspace\MobileTest\dev\nas_arc</nas_archive_unc> </server> <mod_minutes>0</mod_minutes> <variables> <variable> <name>email_report</name> <value>duser@dummy.com</value> </variable> </variables> </config> ######## Loading with ForceArray####### Log::Log4perl->easy_init({ # Log level: (DEBUG INFO WARN ERROR FATAL) level=>$DEBUG, layout=>'%d %H FEFM.%P %p > %m%n', file=>">>" . $mSettings->{err_file}, ForceArray => [ "server" ] }); $mLogger = get_logger(); ######### reading the hash ############### foreach my $server_name (@{$mSettings->{server}}) { my $this_srv = $mConf->{server}->{$server_name}; our_exit('SERVER') if(!defined $this_srv); if($this_srv->{active} ne 'true') { ##This is where i am getti +ng the error our_exit('ACTIVE'); next; # process next server }

Replies are listed 'Best First'.
Re: XML::Simple ForceArray
by monkey_boy (Priest) on Jan 12, 2006 at 13:59 UTC
    Your question is about XML::Simple, but i dont see any code showing what you are doing with the module,
    unless im very confused, the ForceArray => [ "server" ]
    should be the arguments to your XML::Simple call e.g.:
    my $ref = XMLin($xml_file, ForceArray => ["server"]); use Data::Dumper; print Dumper $ref;


    This is not a Signature...
Re: XML::Simple ForceArray
by dev2dev (Initiate) on Jan 12, 2006 at 13:43 UTC
    here is the sample input file
    <?xml version="1.0" ?> <!DOCTYPE config SYSTEM "fefm_config.dtd"> <config> <server name="example_only" active="true"> <fe_logs_unc>\\corp.dummy.com\dev\General_CIFS_Workspa +ce\MobileTest\dev\fe_logs</fe_logs_unc> <fe_shts_unc>\\corp.dummy.com\dev\General_CIFS_Workspa +ce\MobileTest\dev\fe_shts</fe_shts_unc> <fe_archive_unc>\\corp.dummy.com\dev\General_CIFS_Work +space\MobileTest\dev\fe_arc</fe_archive_unc> <nas_repository_unc>\\corp.dummy.com\dev\General_CIFS_ +Workspace\MobileTest\dev\nas_rep</nas_repository_unc> <nas_archive_unc>\\corp.dummy.com\dev\General_CIFS_Wor +kspace\MobileTest\dev\nas_arc</nas_archive_unc> </server> <mod_minutes>0</mod_minutes> <purge_days_remote>30</purge_days_remote> <purge_days_central>30</purge_days_central> <variables> <variable> <name>email_report</name> <value>duser@dummy.com</value> </variable> <variable> <name>email_alert</name> <value>duser@dummy.com</value> </variable> <variable> <name>copy_retry_count</name> <value>3</value> </variable> <variable> <name>move_retry_count</name> <value>3</value> </variable> <variable> <name>sht_summary_unc</name> <value>\\corp.dummy.com\dev\General_CIFS_Workspace\M +obileTest\dev\sht_sum</value> </variable> <variable> <name>stop_time</name> <value>02:00</value> </variable> <variable> <name>mail_server</name> <value>intmail.dummy.com</value> </variable> <variable> <name>mail_sender</name> <value>duser@dummy.com</value> </variable> <variable> <name>pause_length</name> <value>10</value> </variable> </variables> </config>