Open Source Development Tutorials | Newsletter Signup | About Us
Search  

Go Back   Open Source Tutorials Forum > Programming Languages > Perl Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-23-2005, 01:22 AM
NandKishore NandKishore is offline
Junior Member
 
Join Date: Dec 2005
Posts: 1 NandKishore is on a distinguished road
Default Arguements @ Runtime

Dear All ,

I am a newbie to Perl world. I am trying to create a script get_details.pl which can take 3 different options at runtime -d <Number>, -m <Number>, -a. How do I handle them in my script.

That is user can run this script as follows.

get_details.pl -d <NUMBER>
get_details.pl -m <NUMBER>
get_details.pl -a

These are the only valid options available. Also these options are exclusive that is if the user is using the -d option then they cannot use the -m or -a option. What is the most effecient way of handling this kind of logic. Do I have to always use SHIFT or is there a effecient way out.

Thanks a lot.

Nand Kishore
Reply With Quote
  #2  
Old 12-28-2005, 08:28 AM
md_doc md_doc is offline
ubergeek
 
Join Date: Oct 2003
Posts: 204 md_doc has disabled reputation
Lightbulb

Perl arguments are stored in an array called @ARGV

If you want to access the first argument you would reference it as $ARGV[0]. The second argument would be $ARGV[1];

So you might want to do something like.

Code:
switch ($ARGV[0])  {
   case "-a" { maybe call the function for a? }
   case "-m" { maybe call the function for m? }
   case " -d" { maybe call the function for d?}
   else { print "valid arguments are -a or -m [number] or -d [number]\n" }
}


then when you call the -m and -d function just pass $ARGV[1] and make sure it is a number or else return an error there.

Just an idea but it should at least get you started in the right direction.
__________________
md
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 11:17 PM.


Powered by: vBulletin Version 3.0.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright 2004 - 2006 GrindingGears.com. All Rights Reserved.