Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: conditional statements in list constructors

by AnomalousMonk (Archbishop)
on Mar 27, 2014 at 14:05 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found