http://qs1969.pair.com?node_id=1079916

Don Coyote has asked for the wisdom of the Perl Monks concerning the following question:

Writing a program to rename copied photos throughout several folders I am using several greps, at one stage I needed to filter a folder, rather than add another layer of grep I placed an if conditional inside an anonymous list constructor, and discovered that the ?: tertiary conditional may not actually be a synonym for if.

There is most likely a simple reason why the if statement(term/expression?) produces a syntax error if used inside a refto/list constructor, but I wondered if this was due to greater reason than being condusive to writing better code? (as in, hint: use if to control flow not determine variables)

from my examples here, I summise that the tertiary conditional is an if statement(term/expression), wrapped in a do block. Is this the case?

my @arr = ( if(1<2){'1'}else{()} ); #syntax error my $arrref = \( if(1<2){'1'}else{()} ); #syntax error my $arrref2 = [ 1<2 ? '1' : () ]; #works my @arr2 = ( do { if(1<2){'1'}else{()} } ); #works if(1<2){print '1',$/ }else{print '2',$/}; #works 1<2 ? print '1',$/ : print '2',$/; #works ( 1<2 ? print '1',$/ : print '2',$/ ); #works ( if(1<2){print '1',$/ }else{print '2',$/} ); #syntax error