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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:18:18+00:00 2026-05-19T13:18:18+00:00

I am wanting to add the ability for my concept script to iterate the

  • 0

I am wanting to add the ability for my concept script to iterate the same loop of commands over a list of servers, rather that over just one server.

Is it safe to have a foreach loop inside of a foreach loop. Or is there another way to do this?

# Create an empty hash table for discovered virtual machines

my %virtual_machines = ();


my @getallvms = $ssh1->capture('vim-cmd vmsvc/getallvms');

# Remove first line from ESX\ESXi output

shift @getallvms;

# Collect data from ESX\ESXi output
foreach my $server (@servers) {
    foreach my $vm (@getallvms) {

    # Match ID, NAME and VMX file name

    $vm =~  m/^(?<ID> \d+)\s+(?<Name> \S+)\s+\[.+?\]\s+.+?\/(?<VMX> .+?\.vmx)/xm;

    my $id = "$+{ID}";

    my $name = "$+{Name}";

    # Find the absolute path to the VMX file for each virtual machine

    my $vmx_location = $ssh1->capture("find -name $+{VMX}");
    }
}

That is a piece of my script and the basic concept I want to achieve as per the first response.

  • 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-19T13:18:19+00:00Added an answer on May 19, 2026 at 1:18 pm

    Yes, it’s safe. However, you will probably want to use different loop variables other than the default $_.

    foreach my $server (@servers) {
       foreach my $command (@commands) {
           # ...
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following that will enumerate over the model and add an invoice
I'm wanting to remove a space between any two words and add anything that
I'm wanting to add a class to the body tag without waiting for the
I'm wanting to add a search box onto my website - which is built
The company I work for is wanting to add blog functionality to our website
We're wanting to add some properties to our MOSS user profiles and expose them
I have a pretty simple form that I am wanting to localize (I actually
Greetings. I have an RDLC file and am wanting to add a data source
I have a custom gallery plugin that I have created and I am wanting
I have a page that changes hashes quite a bit, and I'm wanting to

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.