Reading from command line

N

Naina

Hi ,
I am trying to read parameters from the command line.
I enter -instrType"S2234".I need to extract s2234 and store in Say
$test.
I am able to separate -instrType as shown below ,but I am unable to
remove the quotes and extract S2234 .

my $instrType = " -instrType\"S2234\"";
$instrType = substr($element,10);

I am new to perl.Any suggestions would help.
Thanks
Naina
 
M

Michael Korte

I am trying to read parameters from the command line.
I enter -instrType"S2234".I need to extract s2234 and store in Say

just leave the quotes.
I would use getopts - it is a perl standard module you can use easily to
get
parameters by commandline. Here is an example :

#STARTSCRIPT
#!/usr/bin/perl
use Getopt::Std; # Standard

if(!getopts('i:')) # In brackets type all letters being parameters
(colon will take a parameter after -i)
{
$test=$opt_i;
}
#ENDSCRIPT

now start your script :
scriptname -i S2234

thats it

in case you need the brackets (becaus of more words / space )
here is a little regex - but there might be a better way :)

while($test =~ "\"")
{
$test =~ s/\"//; # replace " with no letter
}

For more info on getopt have a look at :

http://2robots.com/man/index.php?Getopt::Std

HTH

Michael
 
N

Naina

Hi,
I guess I was not clear in my previous messge.I run the follwing form
command line......builrelease.plx is my build script...........I have
various parameters which I extract from the command line.........For
example I need to enter the below parameters like
-instrtype"s2234"
-model2234
tips
setup etc.........
The flexibility I need is I dont need to enter these parameters in
this particular order.I have to further check for string match
-instrType and then extract s2234 which will be used in my sript in
various places.The same applies to -model2234.
I am able to separate "s2234",but I need to discard the quotes.How do
I go about it?
Any help would be welcome. I am a beginner in perl programming.
Thanks
Naina
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top