Lexicals within statement conditionals

2001-07-30 Thread Bryan C . Warnock
Yes, this is semi-related to the 'my $a if 0;' behavior. Out of morbid curiosity (since I'm working on documentation), given the program that the following program generates: #!/your/path/to/perl -w# perl 5.6.1 my @l = ('a' .. 'g'); my $my = 0; for my $v (@l) { my @a = map { \$$v .=

Re: Lexicals within statement conditionals

2001-07-30 Thread Me
In a nutshell, you are viewing: foo if bar; as two statements rather than one, right? Personally, I think it's more natural to view the above as one statement, so any my anywhere in one element of it does not apply to other elements of it.

Re: Lexicals within statement conditionals

2001-07-30 Thread Dave Mitchell
Out of morbid curiosity (since I'm working on documentation), given the program that the following program generates: #!/your/path/to/perl -w# perl 5.6.1 my @l = ('a' .. 'g'); my $my = 0; for my $v (@l) { my @a = map { \$$v .= '$_' } @l; $a[$my++] = my $a[$my]; print

Re: if then else otherwise ...

2001-07-30 Thread Bart Lateur
On Sun, 29 Jul 2001 19:36:43 -0400, Bryan C. Warnock wrote: $x = ($default,$a,$b)[$b=$a]; # Much like I did before Note that $x = cond? a : b does lazy evaluation, i.e. the value for a or for b is only fetched when it's actually needed. In your construct, they're all fetched anyway,

Re: Lexicals within statement conditionals

2001-07-30 Thread Bryan C . Warnock
On Monday 30 July 2001 05:37 am, Me wrote: In a nutshell, you are viewing: foo if bar; as two statements rather than one, right? Yep. The 5.7 docs explain it rather well, I think. Too bad I didn't read them until *after* I had posted and taken off for work. -- Bryan C. Warnock

Re: if then else otherwise ...

2001-07-30 Thread Bryan C . Warnock
On Monday 30 July 2001 07:29 am, Bart Lateur wrote: On Sun, 29 Jul 2001 19:36:43 -0400, Bryan C. Warnock wrote: $x = ($default,$a,$b)[$b=$a]; # Much like I did before Note that $x = cond? a : b does lazy evaluation, i.e. the value for a or for b is only fetched when it's actually

Re: if3 then else otherwise ...

2001-07-30 Thread Edward Peschko
On Mon, Jul 30, 2001 at 08:23:12PM -0500, David L. Nicol wrote: raptor wrote: hi, we have = and 'cmp' operators but we don't have the conditional constroct to use better their result : May be forthcomming switch will solve this in some way, but isn't it better to have shortcut

Re: if3 then else otherwise ...

2001-07-30 Thread Ted Ashton
Thus it was written in the epistle of Edward Peschko, Maybe call it if3 print do { if3($A cmp $B){ They're the same }{ $A is before $B }{ $B is before $A } };

Re: if3 then else otherwise ...

2001-07-30 Thread Edward Peschko
Ed, Why should it die a horrible death? It seems like something which could be pretty easily implemented: sub if3 ($) { return {$_[1]} unless $_[0]; return {$_[2]} if $_[0] 0; return {$_[3]}; } gives the functionality. A little more research (and perhaps a quick

Re: if then else otherwise ...

2001-07-30 Thread Michael G Schwern
On Sat, Jul 28, 2001 at 04:34:46PM +0300, raptor wrote: if (cond) { } else {} otherwise {} i.e. if cond == 1 then 'then-block' if cond == 0 then 'else-block' if cond == -1 then 'otherwise-block' Sounds like you need a switch, yes. The cases where cond will be 1, 0 and -1 is

Re: if3 then else otherwise ...

2001-07-30 Thread Ted Ashton
Thus it was written in the epistle of Edward Peschko, ok, never mind. I got the impression that this was a built-in function, ie: if3 goes along with = the same that ()? : goes along with if() else. I have no problem if it follows from prototypes. Maybe we could implement '??' along the