bobn has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE: else: is a label. my bad.
So I'm learning Python. I always disdained it because no curlies, but once you start doing stuff in it you get used to it. Sort of
But I still use Perl when I want to cobble something up quick. Using multiple languages has it's issues, though. I get confused. Here's one case where Perl seems to be confused, too, at 5.26.1. I installed perlbrew and it still happens at 5.032000 and 5.033001
#!/usr/bin/perl print "Perl version is: $]\n"; use strict; use warnings; if ( 1 ) { warn "there can only be one, and it's in the IF clause\n" } else: # beware that colon!!!! that's Python, not Perl!!! { warn "there can only be one, and it's in the ELSE clause\n" }
produces
Perl version is: 5.026001 there can only be one, and it's in the IF clause there can only be one, and it's in the ELSE clause Perl version is: 5.032000 there can only be one, and it's in the IF clause there can only be one, and it's in the ELSE clause Perl version is: 5.033001 there can only be one, and it's in the IF clause there can only be one, and it's in the ELSE clause
No warnings, no syntax errors, nothing except the (seemingly) impossible behavior
Removing the colon from the else statement restores correct behavior. gvim didn't catch it either - it's syntax highlighting is as if this was perfectly valid.
Is this a bug, or am i being persnickety?
--Bob
All code given here is UNTESTED unless otherwise stated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Python gave me a colonic
by Paladin (Vicar) on Aug 24, 2020 at 22:46 UTC | |
by LanX (Saint) on Aug 24, 2020 at 23:21 UTC | |
by bobn (Chaplain) on Aug 25, 2020 at 00:50 UTC | |
|
Re: Python gave me a colonic
by LanX (Saint) on Aug 25, 2020 at 00:14 UTC | |
|
Re: Python gave me a colonic (solved - brainfart)
by perlfan (Parson) on Aug 25, 2020 at 02:14 UTC |