I have a string "sample.1.csv.main" want to split into array from 2nd element.
Here is the code I had tried
Code --
my $str = "sample.1.csv.main"; my @arra = split('.',$str,2); print "first element : $arr[0]";
OUTPUT :
first element : sample
DESIRE OUTPUT :
first element : sample.1
Split on dots, then join the first two elements:
my $str = 'sample.1.csv.main'; my @arra = split /./, $str; splice @arra, 0, 2, join '.', @arra[0, 1];
See join and splice.
2.1m questions
2.1m answers
60 comments
56.9k users