Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: conditional statements in list constructors

by AnomalousMonk (Bishop)
on Mar 27, 2014 at 14:05 UTC ( #1079930=note: print w/replies, xml ) Need Help??


in reply to conditional statements in list constructors

... the tertiary conditional is an if statement(term/expression), wrapped in a do block.

The "tertiary conditional" is a conditional expression: it evaluates to one thing or else another thing. It may produce an effect like that of a  do { ... } block, but I would say it is incorrect to say it is a do-block. (Update: E.g., the  + operator produces a result like that of a do-block with some arithmetic operations in it, but it makes no sense to say it is a do-block.) What does the decompiler say?

Update: Added example. (Update: Changed example to include do-block in list.)

c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 1; ;; my @ra = ( 'x', $x ? 'foo' : 'bar', 'y', do { if ($x) { 'biz' } else { 'boz' } } ); print qq{@ra}; " x foo y biz c:\@Work\Perl\monks>perl -wMstrict -MO=Deparse,-p -le "my $x = 1; ;; my @ra = ( 'x', $x ? 'foo' : 'bar', 'y', do { if ($x) { 'biz' } else { 'boz' } } ); print qq{@ra}; " BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } use strict 'refs'; (my $x = 1); (my(@ra) = ('x', ($x ? 'foo' : 'bar'), 'y', do { if ($x) { 'biz'; } else { 'boz'; } })); print("@ra"); -e syntax OK

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1079930]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-05-27 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (98 votes). Check out past polls.

    Notices?