Thread overview
Perl's if and unless
May 21, 2004
Brian Hammond
May 21, 2004
Juan C
May 21, 2004
Stephen Waits
May 22, 2004
Walter
May 22, 2004
Brian Hammond
May 22, 2004
Phill
May 21, 2004
I've never really liked Perl's general appearance except for its alternate if and unless constructs.

These have the structure:

<statement> if <condition>;

<statement> unless <condition>;

e.g.

print "INFO: this is a message\n" if $verbose && $debug_level >= DBG_INFO;

process_input() unless length $input == 0;

The alternate if construct is equivalent to the D:

if (<condition>)
{
<statement>;
}

The alternate unless construct is equivalent to the D:

if (! <condition>)
{
<statement>;
}

I really like the unless because it reads so well.

"do this unless this is true"

I would think this bit of syntactic sugar wouldn't be too hard to add to D since it's just a simple transformation.

I apologize if this has been requested and debated already.

Brian


May 21, 2004
<snip>
><statement> if <condition>;
><statement> unless <condition>;
</snip>

Always makes me think of a bomb squad technician in a comedy:

"Now cut the blue wire... <pause> but before you do that..."


May 21, 2004
Juan C wrote:
> <snip>
> 
>><statement> if <condition>;
>><statement> unless <condition>;
> 
> </snip>
> 
> Always makes me think of a bomb squad technician in a comedy:
> 
> "Now cut the blue wire... <pause> but before you do that..."
> 
> 

I have to say that this is one of the ugliest constructs I've ever faced.  :)

--Steve

[glad to say that my perl hacking days are mostly behind me..]
May 22, 2004
"Brian Hammond" <d at brianhammond dot comBrian_member@pathlink.com> wrote in message news:c8lmu2$vdm$1@digitaldaemon.com...
> I really like the unless because it reads so well.
>
> "do this unless this is true"

That just seems backwards to me <g>. I like things to execute forwards, not backwards.


May 22, 2004
>> I really like the unless because it reads so well.
>>
>> "do this unless this is true"
>
>That just seems backwards to me <g>. I like things to execute forwards, not backwards.

Well she's your baby so that's that :-)
Brian



May 22, 2004
"Brian Hammond" <d at brianhammond dot comBrian_member@pathlink.com> wrote in message news:c8mh1p$264r$1@digitaldaemon.com...
> >> I really like the unless because it reads so well.
> >>
> >> "do this unless this is true"
> >
> >That just seems backwards to me <g>. I like things to execute forwards,
not
> >backwards.
>
> Well she's your baby so that's that :-)

Thank god for that. It seems a bit strange to me as well.
I dont like using a  do / while either.

Phill