How to insert separators between columns?

  • A+
Category:Languages

I have columns in @columns:

my @columns =('column1', 'column2', 'column3'); 

and I have separators in @separators:

my @separators = (',', '|'); 

I want to insert the separators between columns, one by one:

column1,column2|column 

my solution is:

(@columns »~» (|@separators,"")).join("") 

Here I have three columns and two separators, and how about insert N-1 separators between N columns?

 


Assuming that @separators has the right number of values, you could use roundrobin.

roundrobin( @columns, @separators ).flat.join() 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: