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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



branh0913
New User

Aug 29, 2012, 12:01 PM

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

  Hello,

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)
nodecount++
commandtest = 'sshconntest -u $nodeArray[nodecount] -s nodeArray[nodecount]'
printf $commandtest
exit
}


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?


FishMonger
Veteran / Moderator

Aug 29, 2012, 12:49 PM

Post #2 of 2 (857 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.
http://search.cpan.org/~jv/Getopt-Long-2.38/lib/Getopt/Long.pm

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