On Tuesday, October 21, 2003 16:01, Kevin Pfeiffer wrote:

>In article <[EMAIL PROTECTED]>, Steve Grazzini wrote:
>
>> On Tue, Oct 21, 2003 at 01:06:44PM -0700, Jeff Westman wrote:
>>> Steve Grazzini <[EMAIL PROTECTED]> wrote:
>>> > On Tue, Oct 21, 2003 at 12:17:17PM -0700, Jeff Westman wrote:
>>> > > # ... but can I do something like....
>>> > > print "first\n" unless ($counter) else { print "second\n";
>>> > 
>>> > Not really.  You could use the conditional operator, though.
>>> > 
>>> >   print $counter ? "second\n" : "first\n";
>>> 
>>> True, but I was looking for a way to do this with a somewhat "buried"
>>> unless keyword.
>> 
>>   print +( qw(second first --> unless <--) )[ not $counter ];
>
>???   :-|
>

I think the author was trying to be cute...  I got a chuckle out of it!

print +( qw(second first --> unless <--) )[ not $counter ];

Basically, you are creating an anonymous (right term?) array, and printing
the "not $counter"'th element.  So if $counter is 0, you print "first",
otherwise you print "second".  The other stuff in the array is there just to
satisfy the "buried" unless requested by the OP.  However, as you see here,
it does not use the keyword "unless", just a string "unless".  The only
elements that will ever be accessed are "second" and "first"...

It could also be written as:

print +( qw(second first) )[ not $counter ];

HTH
Alan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to