in reply to new way to code html?
It took me forever to figure it out, but here is what is happening with your code. The ternary operator ( - ? - : - ) is not being interpreted as you think it is. If you add parentheses, the behavior goes away:
#No longer "works" sub ah{ my $p = my $htmlparagraphelement = shift; ( wantarray ? (my @givearr = print '<',$p,'>') : (my $fizix = '</'.$p.'>') ) }
Instead, what you wrote is being interpreted as this:
#Same as the code without parentheses. sub ah{ my $p = my $htmlparagraphelement = shift; ( wantarray ? (my @givearr = print '<',$p,'>') : (my $fizix ) ) = '</'.$p.'>' }
That's right, in Perl you can assign to a ternary operator expression! This "feature" allows you to assign to one of two different variables based on a conditional.
So, what is happening?
The result: some truly bizarre behavior. It would make a great trick for some obfuscated code. Barring that, you should never, ever, ever (ever!) do it again.
I do intend to ++ your post, though, because this was really fun.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: new way to code html?
by Don Coyote (Hermit) on Nov 21, 2012 at 20:48 UTC |