Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!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.192725.23204@iwarp.intel.com> Date: 28 Mar 90 19:27:25 GMT References: <1121@etnibsd.UUCP> <15290@bfmny0.UU.NET> <1990Mar28.180657.22785@iwarp.intel.com> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 38 In-Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) In article <1990Mar28.180657.22785@iwarp.intel.com>, merlyn@iwarp (Randal Schwartz) writes: | 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. But of course, after testing it (*after* posting it, sigh... :-), I find that I must put parens around length, as in (length), or make it length($_). Sigh. Overloading of the '?' operator bit me again. Sorry for the first posting being incorrect. (And I'm supposed to have this syntax *mastered* by now? :-) I did come up with an additional widget that you might find interesting: @ARGV = ("-eE1","-e","E2","-fF1","-f","F2"); ## for demo purposes sub handle_e { print "e: @_\n"; } sub handle_f { print "f: @_\n"; } while ($_ = shift) { $sub="handle_$1", do $sub ((length)?$_:shift), next if s/^-([ef])//; unshift(@ARGV,$_), last; } Try that. (I actually did, this time... :-) $_="reJ alounPt srhaetchr, ek";s/(..)(.)(..)/(print$2),$3.$1/eg;s/(.)(.)(.)/(print$2),$3.$1/eg;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!"=/