Path: utzoo!mnetor!uunet!steinmetz!ge-dab!codas!ateng!chip From: chip@ateng.UUCP (Chip Salzenberg) Newsgroups: comp.sources.d Subject: Re: How are YOU using perl? Message-ID: <235@ateng.UUCP> Date: 13 Apr 88 17:03:55 GMT References: <720@hadron.UUCP> Reply-To: chip@ateng.UUCP (Chip Salzenberg) Organization: A T Engineering, Tampa, FL Lines: 39 Keywords: perl In article <720@hadron.UUCP> klr@hadron.UUCP (Kurt L. Reisler) writes: >Which would be an appropriate news group for the discussion of uses of >Larry Wall's outstanding "perl" program? I would be intersted in >learning what uses you are putting it to, and what kind of tricks have >been developed. Here is my favorite argument parsing loop: $debug = 0; $verbose = 1; while ($#ARGV >= 0) { $_ = $ARGV[0]; last unless /^-/; # Not an option shift; last if ($_ eq "--"); # End of options s/-//g; if (s/D//g) { $debug = 1; } if (s/s//g) { $verbose = 0; } if (s/v//g) { $verbose = 2; } # Other options go here # By now we should have used all the chars in this argument. if ($_) { print stderr "illegal option", (length($_) > 1 ? "s" : ""), ": -$_\n"; do usage(); exit 1; } } I like it because it doesn't let illegal options pass, and it allows multiple switches in an argument. -- Chip Salzenberg "chip@ateng.UU.NET" or "codas!ateng!chip" A T Engineering My employer's opinions are a trade secret. "Anything that works is better than anything that doesn't."