RE: How to use command-line switches...
This will work for the most part, but I would really recommend against it. Check out the docs for Getopt::Std. It is much simpler than Getopt::Long, and will really end up simplifying your scripts, although it might not seem like it at first look. Here's an example of a script that uses Getopt::Std to put the switches into a hash to use later. The options with a colon after them in the getopts() line take a parameter, and the other ones are on/off switches. An example command line would be: "myscript.pl -s SERVERNAME -o OUTFILE -v" ## use strict; use warnings; use Getopt::Std; my %opt = (); getopts('ho:s:v',\%opt); my $outfile = $opt{o}; if($opt{h}){ Help(); }elsif($opt{v}){ Ver(); } ## -Original Message- From: Miller, Joseph S [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 11:48 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: How to use command-line switches... Richard here is an example of code that gets the switch variables from the command line and checks it before continuing with the script. The shift function is operating on the @_ array and the @_ array contains the parameters passed to that subroutine from the command line(reference perlvar). my $switch = shift; if($switch eq "" or $switch =~ /-u/i) { print "$usagestring"; exit 1; } elsif ($switch =~ /-p/i) { $portnum = shift; } elsif ($switch =~ /-d/i) { $dbalias = shift; } else { print "Invalid argument passed. Try again.\n$usagestring"; exit 1; } Hope it helps. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 1:04 PM To: [EMAIL PROTECTED] Subject: How to use command-line switches... I have a case where I need to use a command-line switch such as -X or /x Could anyone help me with information as to how I read this into a perl script and test it - along the lines of "if "/x" then..." ?? I've searched but can't seem to find any concrete example that a newbie like me can use as a sample. Thank you!! Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to use command-line switches...
No problem, glad to help. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 1:56 PM To: Miller, Joseph S; [EMAIL PROTECTED] Subject: RE: How to use command-line switches... Thank you! This is exactly what I need. The 17 pages in the PERLDOC lib info on Getopt::Long were a bit daunting/intimidating and for me like driving a nail with a shotgun This sample code gives me a really good example that shows the concept! Thank you for sharing it! -Original Message- From: Miller, Joseph S [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 2:48 PM To: Copits Richard; [EMAIL PROTECTED] Subject: RE: How to use command-line switches... Richard here is an example of code that gets the switch variables from the command line and checks it before continuing with the script. The shift function is operating on the @_ array and the @_ array contains the parameters passed to that subroutine from the command line(reference perlvar). my $switch = shift; if($switch eq "" or $switch =~ /-u/i) { print "$usagestring"; exit 1; } elsif ($switch =~ /-p/i) { $portnum = shift; } elsif ($switch =~ /-d/i) { $dbalias = shift; } else { print "Invalid argument passed. Try again.\n$usagestring"; exit 1; } Hope it helps. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 1:04 PM To: [EMAIL PROTECTED] Subject: How to use command-line switches... I have a case where I need to use a command-line switch such as -X or /x Could anyone help me with information as to how I read this into a perl script and test it - along the lines of "if "/x" then..." ?? I've searched but can't seem to find any concrete example that a newbie like me can use as a sample. Thank you!! Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message. Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to use command-line switches...
Thank you! This is exactly what I need. The 17 pages in the PERLDOC lib info on Getopt::Long were a bit daunting/intimidating and for me like driving a nail with a shotgun This sample code gives me a really good example that shows the concept! Thank you for sharing it! -Original Message- From: Miller, Joseph S [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 2:48 PM To: Copits Richard; [EMAIL PROTECTED] Subject: RE: How to use command-line switches... Richard here is an example of code that gets the switch variables from the command line and checks it before continuing with the script. The shift function is operating on the @_ array and the @_ array contains the parameters passed to that subroutine from the command line(reference perlvar). my $switch = shift; if($switch eq "" or $switch =~ /-u/i) { print "$usagestring"; exit 1; } elsif ($switch =~ /-p/i) { $portnum = shift; } elsif ($switch =~ /-d/i) { $dbalias = shift; } else { print "Invalid argument passed. Try again.\n$usagestring"; exit 1; } Hope it helps. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 1:04 PM To: [EMAIL PROTECTED] Subject: How to use command-line switches... I have a case where I need to use a command-line switch such as -X or /x Could anyone help me with information as to how I read this into a perl script and test it - along the lines of "if "/x" then..." ?? I've searched but can't seem to find any concrete example that a newbie like me can use as a sample. Thank you!! Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message. Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to use command-line switches...
Richard here is an example of code that gets the switch variables from the command line and checks it before continuing with the script. The shift function is operating on the @_ array and the @_ array contains the parameters passed to that subroutine from the command line(reference perlvar). my $switch = shift; if($switch eq "" or $switch =~ /-u/i) { print "$usagestring"; exit 1; } elsif ($switch =~ /-p/i) { $portnum = shift; } elsif ($switch =~ /-d/i) { $dbalias = shift; } else { print "Invalid argument passed. Try again.\n$usagestring"; exit 1; } Hope it helps. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 1:04 PM To: [EMAIL PROTECTED] Subject: How to use command-line switches... I have a case where I need to use a command-line switch such as -X or /x Could anyone help me with information as to how I read this into a perl script and test it - along the lines of "if "/x" then..." ?? I've searched but can't seem to find any concrete example that a newbie like me can use as a sample. Thank you!! Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to use command-line switches...
[EMAIL PROTECTED] wrote: I have a case where I need to use a command-line switch such as -X or /x Could anyone help me with information as to how I read this into a perl script and test it - along the lines of "if "/x" then..." ?? perldoc Getopt::Std and perldoc Getopt::Long -- Brett -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to use command-line switches...
I have a case where I need to use a command-line switch such as -X or /x Could anyone help me with information as to how I read this into a perl script and test it - along the lines of "if "/x" then..." ?? I've searched but can't seem to find any concrete example that a newbie like me can use as a sample. Thank you!! Portions of this message may be confidential under an exemption to Ohio's public records law or under a legal privilege. If you have received this message in error or due to an unauthorized transmission or interception, please delete all copies from your system without disclosing, copying, or transmitting this message.