Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!cs.utexas.edu!usc!henry.jpl.nasa.gov!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: getopt Message-ID: <6584@jpl-devvax.JPL.NASA.GOV> Date: 12 Dec 89 19:02:52 GMT References: Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 33 In article emv@math.lsa.umich.edu (Edward Vielmetti) writes: : : how can I use getopt to detect the presence or absence of : a switch? I thought I had it down pat: : : #!/usr/local/bin/perl : : do 'getopt.pl'; : : &Getopt('p'); : : if ($opt_p) { : print STDERR "P option selected\n" ; : } else { : print STDERR "No P option\n"; : } : : picasso /tmp/emv % ./post.pl -q # OK : No P option : picasso /tmp/emv % ./post.pl -p # huh? : No P option : picasso /tmp/emv % ./post.pl -p 1 # OK again : P option selected : : How do I recognize '-p' w/o any argument to it ? The argument to Getopt() specifies the switches that take an argument. You can't have a switch that both does and doesn't take an argument. How would you parse this: ./post.pl -p -q Larry