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 9257971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:16:32+00:00 2026-06-18T12:16:32+00:00

Hello I am trying to insert a new element so that I go from

  • 0

Hello I am trying to insert a new element so that I go from this

   <explicit-group name="CDEV">
      <aip-address>1.1.1.1</aip-address>
      <aip-address>2.2.2.2</aip-address>
      <aip-address>3.3.3.3</aip-address>

To this

   <explicit-group name="CDEV">
      <aip-address>1.1.1.1</aip-address>
      <aip-address>2.2.2.2</aip-address>
      <aip-address>3.3.3.3</aip-address>
      <aip-address>99.99.99.254</aip-address>

The code I have is as follows but I have been reading about references and de referencing for two days and still cant get it. Am I trying to do something impossible or can someone show me how.

Thanks!

use strict;
use XML::Simple;
use Data::Dumper;
my $xs = XML::Simple->new(
  XMLDecl => '<?xml version="1.0" encoding="UTF-8"?>',
  forcearray => [ 'item' ],
  keyattr    => {   },
  rootname   => 'SG-distribution',
);

my $opt = $xs->XMLin(\*DATA);


push @{ $opt->{'sa-coller'}->{'explicit-group'} } , { {'CDEV'}->{'aip-address'} };

print Dumper($opt);
print $xs->XMLout($opt);

__DATA__
<?xml version="1.0" encoding="UTF-8"?><SG-distribution>
  <sa-coller name="W8-C1" enabled="true" host="localhost" port="99">
    <ip-group name="home" ipAddressMask="192.168.0.*" match="glob"/>
    <ip-group name="home2" ipAddressMask="10.0.0.*" match="glob"/>
    <explicit-group name="CDEV">
      <aip-address>1.1.1.1</aip-address>
      <aip-address>2.2.2.2</aip-address>
      <aip-address>3.3.3.3</aip-address>
    </explicit-group>
    <explicit-group name="HYU"/>
    <explicit-group name="JUN"/>
  </sa-coller>
</SG-distribution>
  • 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-06-18T12:16:34+00:00Added an answer on June 18, 2026 at 12:16 pm

    You have an array with four element representing each explicit_group element. You want to identify the one whose name attribute is CDEV. Since they’re not indexed by name (but by position), so you’ll need to iterate over the array to find the right element.

    for my $explicit_group (@{ $opt->{'sa-coller'}{'explicit-group'} }) {
      if ($explicit_group->{name} eq 'CDEV') {
         push @{ $explicit_group->{'aip-address'} }, '99.99.99.254';
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have an array $name[] that I am trying to insert into the
Hello I was trying to remove objects from object array that I have and
Hello Everyone Iam trying to bulk insert data from .dat file(unloaded from sybase) in
hello i am trying to load a list of filenames from a folder into
Hello I'm trying something .. I was reading Jquery traversing documentations some forums, this
I'm trying to use a yui plugin that pulls from a json file and
Hello I am trying to run this oracle query in toad and I am
Hello Stackoverflowers, I'm trying to use a button, that first goes to another excel
Hello im trying to implement this D3 project http://bl.ocks.org/929623 : with images like this
I am trying to create a Javascript file that I can reference from other

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.