[UKLUG] Re: LPM: unless ($line =~ /^#/)

Joe Hourcle oneiros at dcr.net
Mon Jan 1 13:25:46 CST 2001



On Fri, 29 Dec 2000, Rich Bowen wrote:

> Ronald Edward Petty wrote:
> >
> > so can u do
> > unless()
> > {
> > }
> > else
> > {
> > }
> >
> > and else be the say the opposite? kinda like if.
>
> Well, yes, you can do unless, else, but it seems rather backwards. It's
> good style to program as you would speak or think. unless ... else  is
> potentially confusing, and I would think that it would be a good idea to
> avoid it.

Unless may be great for throw-away programs, where you're trying to code
quick, but as you can always negate the test in your condition, it's
normally easier to maintain when you always use 'if'.

Besides, it's fewer keystrokes to type:

	if ($line !~ /^#/)

vs.
	unless ($line =~ /^#/)


-----
Joe Hourcle




More information about the Lexington-pm mailing list