in reply to Splitting on escapable delimiter
so that:sub unroll { my @x = $_[0] =~ /(?:^|@)((?:##|#@|[^#@])*)/g; for(@x){ $_ =~ s/##/#/g; $_ =~ s/#@/@/g; } @x }
produces the following fully unescaped list:unroll("#@##@###@####@#####@")
This approach also has the benefit of handling empty sequences correctly, eg:'@#', '#@##', '##@',
produces:unroll("@@#@##@###@####@#####@")
as it probably should.'', '', '@#', '#@##', '##@'
Apply my_escape to each element of the list and then call my_join on it, so that:sub my_escape { my $x = shift; $x =~ s/#/##/g; $x =~ s/@/#@/g; $x } sub my_join { join('@',@_) }
produces:my_join(map{my_escape($_)}('','','@#','#@##','##@',))
'@@#@##@###@####@#####@'
|
|---|