in reply to Re: Printing Array with quote and comma
in thread Printing Array with quote and comma

Same thing (well, better quoting), but possibly easier to read:
sub bracket { local $_ = @_ ? $_[0] : $_; return "[$_]"; } sub quote { local $_ = @_ ? $_[0] : $_; s/(['\\])/\\$1/g; return "'$_'"; } print map { "$_;\n" } # Add tail. bracket # Surround with brackets. join ',', # Seperate elements with commas. map quote, # Quote elements. @arr; # Elements.
or
sub quote { local $_ = @_ ? $_[0] : $_; s/(['\\])/\\$1/g; return "'$_'"; } print map { "[$_];\n" } # Add brackets and tail. join ',', # Seperate elements with commas. map quote, # Quote elements. @arr; # Elements.