Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:29:23+00:00 2026-05-27T13:29:23+00:00

Hi everyone, This is very simple for perl programmers but not beginners like me,

  • 0

Hi everyone,
This is very simple for perl programmers but not beginners like me,
I have one xml file and I processed using XML::Simple like this

my $file="service.xml";
my $xml = new XML::Simple;
 my $data = $xml->XMLin("$file", ForceArray =>  ['Service','SystemReaction',  
                                      'Customers', 'Suppliers','SW','HW'],);

Dumping out $data, it looks like this:

$data = {
   'Service' => [{
         'Suppliers' => [{
               'SW' => [
                  {'Path' => '/work/service.xml',  'Service' => 'b7a'},
                  {'Path' => '/work/service1.xml', 'Service' => 'b7b'},
                  {'Path' => '/work/service2.xml', 'Service' => 'b5'}]}
         ],
         'Id' => 'SKRM',
         'Customers' =>
            [{'SW' => [{'Path' => '/work/service.xml', 'Service' => 'ASOC'}]}],
         'Des'  => 'Control the current through the pipe',
         'Name' => ' Control unit'
      },
      {
         'Suppliers' => [{
               'HW' => [{
                     'Type'    => 'W',
                     'Path'    => '/work/hardware.xml',
                     'Nr'      => '18',
                     'Service' => '1'
                  },
                  {
                     'Type'    => 'B',
                     'Path'    => '/work/hardware.xml',
                     'Nr'      => '7',
                     'Service' => '1'
                  },
                  {
                     'Type'    => 'k',
                     'Path'    => '/work/hardware.xml',
                     'Nr'      => '1',
                     'Service' => '1'
                  }]}
         ],
         'Id' => 'ADTM',
         'Customers' =>
            [{'SW' => [{'Path' => '/work/service.xml', 'Service' => 'SDCR'}]}],
         'Des'  => 'It delivers actual motor speed',
         'Name' => ' Motor Drivers and Diognostics'
      },
      # etc.
   ],
   'Systemreaction' => [
      # etc.
   ],
};

How to access each elements in the service and systemReaction(not provided). because I am using “$data” in further processing. So I need to access each Id,customers, suppliers values in each service. How to get particular value from service to do some process with that value.for example I need to get all Id values form service and create nodes for each id values.

To get Type and Nr value I tried like this

 foreach my $service (@{ $data->{Service}[1]{Suppliers}[0]{HW}[0] }) {
 say $service->{Nr};
 }
 foreach my $service (@{ $data->{Service}[1]{Suppliers}[0]{HW}[0] }) {
 say $service->{Type};

  }

can you help me how to get all Nr and Type values from Supplier->HW.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:29:23+00:00Added an answer on May 27, 2026 at 1:29 pm

    I suggest reading perldocs Reference Tutorial and References and Nested Data Structures. They contain an introduction and full explanation of how to access data like that.

    But, for example, you can access the service ID by doing:

    say $data->{Service}[0]{Id}   # prints SKRM
    

    You could go through all the services, printing their ID, with a loop:

    foreach my $service (@{ $data->{Service} }) {
        say $service->{Id};
    }
    

    In response to your edit

    $data->{Service}[1]{Suppliers}[0]{HW}[0] is an hash reference (you can check this quickly by either using Data::Dumper or Data::Dump on it, or just the ref function). In particular, it is { Nr => 18, Path => "/work/hardware.xml", Service => 1, Type => "W" }

    In other words, you’ve almost got it—you just went one level too deep. It should be:

    foreach my $service (@{ $data->{Service}[1]{Suppliers}[0]{HW} }) {
     say $service->{Nr};
    }
    

    Note the lack of the final [0] that you had.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple table called genre , which looks like this: GENRE
I have something simple like this: $(selector).append("somestuff"); But since I'm going to reuse the
This is not a new topic, but I am curious how everyone is handling
I feel like this is a simple question, but I am still relatively new
So, I essentially have what I want already, very simple, but there are some
Why does everyone tell me writing code like this is a bad practice? if
My question is very similar to this question but a bit more specific. My
Hey Everyone, This question seems really silly to me, but I can't for the
I'm trying to create a very simple best-fit scheduling system. Everyone submits their free/busy
I would like to create a very simple PHP page for a site, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.