Perl Getopt::Long


 
Thread Tools Search this Thread
Top Forums Programming Perl Getopt::Long
# 1  
Old 05-08-2013
Perl Getopt::Long

Hi All

I am using Getopt::Long in perl and i am trying to have it so if i dont supply a switch after the progname is will do a defult option

i have the following

Code:
GetOptions($OPT,
    'debug|d',
    'mail|m',
) or info();

i want it run the debug if it is not given a switch

Thanks
A

Last edited by Scott; 05-08-2013 at 11:44 AM.. Reason: Code tags, not Icode tags
# 2  
Old 05-08-2013
You could simply do this:
Code:
if (@ARGV == 0) { &debug }

sub debug {
    <code>
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl :: Getopt::Long in the program

While going through some of the perl script... I had found the below line.. use Getopt::Long; my $GetOptionsReturnCode = GetOptions ( '<>' => sub { push(@unknownArg, @_); }, 'h|help' => sub { &helpMessage(); exit 0; }, ); Could anyone please explain the above one ... (1 Reply)
Discussion started by: scriptscript
1 Replies

2. Shell Programming and Scripting

Still thin Perl is long winded and cumbersome to use ...

grep " $1 " completelist if then echo "$1 not found." fi Is there a Perl solution that just as short sweet and fast ? (1 Reply)
Discussion started by: popeye
1 Replies

3. Shell Programming and Scripting

Inserting into long delimited string using perl.

Hi, I have a very long pipe delimited string. The length of the string could vary. For example: START|one|two|three|four|five|six|seven START|one|two|three|four|five|six|seven|eight|nine START|one|two|three|four I want to replace in the third occurence of string with another... (9 Replies)
Discussion started by: som.nitk
9 Replies

4. Shell Programming and Scripting

How long ago since time - Using perl

echo "1337124526" | perl -pe 's/(\d+)/easttime($1)/e' the above gives a date and time. how can i subtract the date and time given by this command, from the current present date? can this be a one liner or as close to a one-liner as possible? (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

Perl Getopt::Long question - stopping multiple args

Hi there, I have an example basic script (below) and ive been trying to figure out how to stop multiple arguments to my options occuring. for example using the example script below I can issue two arguments for, say the --surname option and it will not barf at me (although thats what i want it to... (11 Replies)
Discussion started by: rethink
11 Replies

6. Shell Programming and Scripting

using getopt for both short and long options

Hi , I am using getopt for both short and long options as below SHORTOPTS="a:c" LONGOPTS="alpha:,charlie" OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "$progname" -- "$@") eval set -- "$OPTS" while ; do case $1 in -a|--alpha) echo "-a or --alpha... (1 Reply)
Discussion started by: padmisri
1 Replies

7. Shell Programming and Scripting

using getopt for both short and long options

Hi , I am using getopt for both short and long options as below SHORTOPTS="a:c" LONGOPTS="alpha:,charlie" OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "$progname" -- "$@") eval set -- "$OPTS" while ; do case $1 in -a|--alpha) echo "-a or --alpha... (1 Reply)
Discussion started by: padmisri
1 Replies

8. Shell Programming and Scripting

using getopt for both short and long options

Hi , I am using getopt for both short and long options as below SHORTOPTS="a:c" LONGOPTS="alpha:,charlie" OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "$progname" -- "$@") eval set -- "$OPTS" while ; do case $1 in -a|--alpha) echo "-a or --alpha... (0 Replies)
Discussion started by: padmisri
0 Replies

9. Shell Programming and Scripting

getopt in perl

Hi, I have a perl script with two functions say func a and func b. sub a { ----------- --------- } sub b { --------- --------- } I want to use this function on command line as we can do in shell script using getopt. My motto here is to run the script like this ... (7 Replies)
Discussion started by: namishtiwari
7 Replies

10. Shell Programming and Scripting

Perl - How do you break the long line of codes into 2?

I'm trying to make this long line of codes in Perl looks nice by dividing it into 2 lines... Before: `echo "blahblahblahblahblahblahblahblahblahblahblah" > ~/lalala/lalala/lalala/lalala/lalala/abc`; After: `echo "blahblahblahblahblahblahblahblahblahblahblah" > ... (5 Replies)
Discussion started by: teiji
5 Replies
Login or Register to Ask a Question