Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Joining if an array

by Mutant (Priest)
on May 01, 2009 at 15:37 UTC ( #761317=note: print w/ replies, xml ) Need Help??


in reply to Joining if an array

I might be tempted to use the ternery operator, but usually for a non-trivial assignment (like a join) I'd avoid it as it just gets messy. I'd probably do:

my $in; if (ref $scalar eq 'ARRAY') { $in = join(",",@$scalar); } else { $in = $scalar; }
Not short, but pretty clear in what I mean (hopefully).


Comment on Re: Joining if an array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2015-07-02 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (46 votes), past polls