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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:26:29+00:00 2026-05-20T05:26:29+00:00

I have a sub routine that creates an array of IP addresses, however I

  • 0

I have a sub routine that creates an array of IP addresses, however I do not know how many IPs will be pushed into the array. (based on how many matches in a txt file) Then I have another sub that needs to pull each IP address from the array and assign a variable. all IPs will be printed in the same line of output. I want to do something like this:

@IPS = ("1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4");  
print "vserver1 $IPS[0], vserver2 $IPS[1], vserver3 $IPS[2], vserver4 $IPS[3]\n";    

The problem is, I won’t know how many IPs will be in the array. How do I call an unknown number of values? Is it possible to assign a variable to the first IP, then the same variable assigned to the second IP the next time I call it?

print "vserver1 $IPS, vserver2 $IPS, vserver3 $IPS, vserver4 $IPS\n";  

thanks in advance!

  • 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-20T05:26:30+00:00Added an answer on May 20, 2026 at 5:26 am

    It is technically possible to do what you are asking, but it is not a good solution for this problem. Because even if a magic $IPS variable would walk along the array with each access, you would still not have the vserver# portion of your output.

    Instead, why not write a loop to process the array:

    print join(', ' => map {"vserver$_ $IPS[$_ - 1]"} 1 .. @IPS ), "\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have a subroutine in Perl that fills an array with some information.
I'm developing a website which to begin with will have three clear sub sites:
I have a domain and a group of sub-domains that require authentication to access.
I have a subroutine that takes a filehandle as an argument. How do I
I have classX: Sub New(ByVal item_line_no As String, ByVal item_text As String) ' check
i have a sub with this signature Public Sub Save(ByVal obj As IPta) now
I have a folder FolderA which contains three sub-folders: foldera1 foldera2 and foldera3 I
I have a main form and as sub form. I need the main Form
I have the following code in my class : sub new { my $class
I have a WinForms TreeView with one main node and several sub-nodes. How can

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.