Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: conditional statements in list constructors

by SuicideJunkie (Vicar)
on Mar 27, 2014 at 14:59 UTC ( #1079939=note: print w/replies, xml ) Need Help??


in reply to conditional statements in list constructors

If you want to conditionally include things in a list, try the x!! operator combo:

my $pi = 0; my $life = 'isgood'; my $foo = 1; my $aref = [ (3,1,4) x !!($pi), (42) x !!($life), ('bar', 'baz') x !!( +$foo) ]; print Dumper $aref;
gives:
$VAR1 = [ 42, 'bar', 'baz' ];

Log In?
Username:
Password:

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

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



    Results (76 votes). Check out past polls.

    Notices?