In the below code, I am trying to split between two numbers. The splitting is not functioning correctly. For eg: when I split between 0 and 1, the split also occurs in between digits of 10 and 11.
Can some one help me in this?
use strict;
use warnings;
my $j= "0,2,3,6,5,1,4,7,8,12,11,10,9";
my $k=1; my $k1=0,;
my @ar=split(/($k|$k1)/,$j);
print join(";",@ar);
Expected result:0;2,3,6,5;1;4,7,8,12,11,10,9
Above code result: 0;,2,3,6,5,;1;,4,7,8,;1;2,;1;1;,;1;0;,9
First, you don’t want to split on 0 or 1, you want to split on a commas next to the number
0or1.