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

  • Home
  • SEARCH
  • 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 8916167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:10:01+00:00 2026-06-15T05:10:01+00:00

i am running a Vmware script where it goes half way through and then

  • 0

i am running a Vmware script where it goes half way through and then fails with below error and exits:

Can't use an undefined value as an ARRAY reference at test.pl line 49.

This is running on a vCetner inventory which has ~4000 VMs. So I want the script to ignore such erros and continue running until it finishes. At the moment the script exits withouht any ouput after above error.

here is my code which gives me the above error. I am pasting only few lines where the error arises from:

foreach my $vm_mo_ref ( @{ $host_view->vm } )
{
        print $vm_mo_ref."\n";
}

This is what I did to ignore the error:

foreach my $vm_mo_ref ( @{ $host_view->vm } )
{
    if (defined $vm_mo_ref)
    {   
            print $vm_mo_ref."\n";
    }
}

and

foreach my $vm_mo_ref ( @{ $host_view->vm } )
{
    if (exists $vm_mo_ref)
    {   
            print $vm_mo_ref."\n";
    }
}

and

foreach my $vm_mo_ref ( @{ $host_view->vm } )
{
    if ($vm_mo_ref)
    {   
            print $vm_mo_ref."\n";
    }
}

and

foreach my $vm_mo_ref ( @{ $host_view->vm } )
{
    if (ref($vm_mo_ref) eq "ARRAY")
    {   
            print $vm_mo_ref."\n";
    }
}

and

foreach my $vm_mo_ref ( @{ $host_view->vm } )
{
    if (ref($vm_mo_ref) eq "ManagedObjectReference")
    {   
            print $vm_mo_ref."\n";
    }
}

However, none of above five approaches with “if” condition are working and my script still fails/exits with aforementioned error.

BTW, ManagedObjectReference is Vmware specific reference.

Could you help me get around this error and continue with the rest of the script.
Thanks.

  • 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-15T05:10:03+00:00Added an answer on June 15, 2026 at 5:10 am

    Try

    foreach my $vm_mo_ref ( @{ $host_view->vm || [] } )
    

    Nothing you change in the loop will have any effect because your code throws an exception before it even enters the loop.

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

Sidebar

Related Questions

Running my script through Devel::NYTProf showed that the following portion of code took up
I have a perl script running on a Debian virtual machine on VMWare. This
I have a linux running on VMWare, and I use gdb in the host
I am working in Windows and running fedora through VMware. By default, the kernel
I've been running VMWare fusion for awhile now and use it to create new
How can I disable PXE network booting through vSphere on a virtual machine running
I am running backtrack on vmware,while running windows 7 as base operating system.Can I
I currently use a linux VM in VMWare running on a Windows machine. I
We're running the latest versions of VMWare Player and Workstation for Windows. The following
I'm running ubuntu 11.10 on a vmware 4.0 player. I'm having a problem and

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.