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

Wanting to add a thumbs up/down rating system to my Tumblr Page, just like
I'm wanting to add a listener to my ListView that would detect when a
I've got a String array that I'm wanting to add to a string builder
I'm wanting to add new comments to a list of existing comments on page.
Is it possible to add something to the list of items that shows up
hi im wanting to know how to add google maps into a list view?
Ok so I am wanting to add the ability for users to use their
I'm wanting to add objects to a vector representing an argument list in Yacc/Bison.
I was wanting to add some components and generic code that I made in
I often face the problem of wanting to add additional methods to classes I

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.