CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Passing arrays through command line args


New User

Aug 29, 2012, 12:01 PM

Post #1 of 2 (1374 views)
Passing arrays through command line args Can't Post


I'm working on a project to test our ssh ability to connect, but I have literally hundreds of different profiles. I'm very new to perl, but I wanted to test this via a script (and get my feet wet). Basically for every one of my clusters I have a user profile, if the cluster is say c30, the I may have have something like 4 nodes in the c30 cluster. For example c30 may have a name like c30g1 c30g2, etc.

so basically if I have a command line, it would be like this

sshconntest -u c30g2 -s c30g2

I originally tried to assign array like so

@nodeArray = (c30g1,c30g2);
nodecount = 0
while (@nodeArray > scalar @nodeArray)
commandtest = 'sshconntest -u $nodeArray[nodecount] -s nodeArray[nodecount]'
printf $commandtest

This doesn't run, but in the past I've got this to work, it only grabs the first element in the array, and not the second one. Also in some cases like in the above example, it will say that nodecount is not numeric. I'm not sure how arrays work here, but is there anyway where I can pass an entire array into the commandline args?

Any "best practices" when dealing with arrays that I should follow?

Veteran / Moderator

Aug 29, 2012, 12:49 PM

Post #2 of 2 (1373 views)
Re: [branh0913] Passing arrays through command line args [In reply to] Can't Post

First, I'd use the Getopt::Long module to handle the parsing of the command line args. The module makes it very easy to accept multiple args and load them into an array.

If your list/cluster is more than the few nodes that you mentioned, then passing each of them as args is fine. However if the cluster contains more than few nodes, then it would be best to create a config file of the clusters and pass the "cluster name" as the arg and use that to load the node list from the config file.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives