Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: quasi-bug Message-ID: <1990Mar28.180657.22785@iwarp.intel.com> Date: 28 Mar 90 18:06:57 GMT References: <1121@etnibsd.UUCP> <15290@bfmny0.UU.NET> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 34 In-Reply-To: flee@shire.cs.psu.edu (Felix Lee) In article , flee@shire (Felix Lee) writes: | Perl is kinda dangerous in many ways. s/kinda //; # :-) | I once wanted to parse multiple '-e expr' and '-f file' options the | way 'sed' does, with or without a space between the option and the | argument. Without much thought, I wrote the following, which handles | the optional space in a single statement: | while ($_ = shift) { | &expression($1 || shift), next if (/^-e(.*)$/); | &file($1 || shift), next if (/^-f(.*)$/); | # ... | } | Unfortunately, this doesn't work properly for '-e0', '-f0', or '0'. | | If strings weren't converted to numbers in boolean contexts . . . while ($_ = shift) { &expression(length ? $_ : shift), next if s/^-e//; &file(length ? $_ : shift), next if s/^-f//; # ... } I just came up with this while replying. Lemme know if you like it. I like it so far... it looks pretty clean and direct. $_ = "Just a sed user,";s/a/another/;s/sed/Perl/;s/user/hacker/;print -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/