in reply to Re: Printing Array with quote and comma
in thread Printing Array with quote and comma
orsub 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.
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.
|
|---|