in reply to Joining if an array
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 |