in reply to Joining if an array

Here's one line that does exactly the same thing as your code using the ternary Conditional Operator.

my $in = ($scalar =~ /array/i) ? join(",",@$scalar) : $scalar;

Update: It occurs to me that by using a regex there, you are opening yourself up to a bug if $scalar contains the substring "array", so you should probably use the ref operator. And as Mutant points out below, if you are going for prettiness and legibility, an if-else is far clearer in intent than ? will be.

Replies are listed 'Best First'.
Re^2: Joining if an array
by Rodster001 (Pilgrim) on May 01, 2009 at 17:06 UTC
    Good point. I've used a regexp out of habit for a long time... from here on out I'll use ref().