io has asked for the wisdom of the Perl Monks concerning the following question:
Much like one would do it in c. Now i found this way, which is much nicer:for($i=0; $i<@ARGV; $i+=2) { $ip = $ARGV[$i+1] if $ARGV[$i] eq '-i' || $ARGV[$i] eq '--ip'; $port = $ARGV[$i+1] if $ARGV[$i] eq '-p' || $ARGV[$i] eq '--port'; }
Note that i expected shift @ARGV would work. Oh well. How would you do it? Thanks for your wisdom :-)while(@ARGV) { $_ = shift @ARGV; $ip = shift @ARGV if /-i/ || /--ip/; $port = shift @ARGV if /-p/ || /--port/; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing commandline arguments
by djantzen (Priest) on Feb 12, 2002 at 13:37 UTC | |
|
Re: parsing commandline arguments
by dreadpiratepeter (Priest) on Feb 12, 2002 at 14:22 UTC | |
|
Re: parsing commandline arguments
by grinder (Bishop) on Feb 12, 2002 at 16:28 UTC | |
|
Re: parsing commandline arguments
by jonjacobmoon (Pilgrim) on Feb 12, 2002 at 14:24 UTC | |
|
Re: parsing commandline arguments
by io (Scribe) on Feb 12, 2002 at 21:42 UTC | |
|
Re: parsing commandline arguments
by pizza_milkshake (Monk) on Feb 12, 2002 at 14:23 UTC |