Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!math.lsa.umich.edu!sharkey!itivax!scs From: scs@itivax.iti.org (Steve Simmons) Newsgroups: comp.lang.perl Subject: Re: getopt Message-ID: <4644@itivax.iti.org> Date: 12 Dec 89 21:38:53 GMT References: <6584@jpl-devvax.JPL.NASA.GOV> Organization: Industrial Technology Institute, Ann Arbor, MI. Lines: 38 lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: >In article emv@math.lsa.umich.edu (Edward Vielmetti) writes: >: >: 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 There do exist a number of switches which take optional trailing arguements with a default assumed when the trailer isn't there. The getopt() function distributed by AT&T handles this correctly, with optarg (I think that's the name) being NULL. Way back when AT&T was suggesting a standard for switch parsing, this was allowed. A real-world example: cc -O means optimse the program to level 2, while cc -O3 means use level 3. -- Steve Simmons scs@iti.org Industrial Technology Institute '"You're not a big name on Usenet until someone puts you in their .sig file." -- Anonymous'