I have a sequence that looks like this:
my $seq = "D\IKLR\LK/Q";
what I want to do is to break the sequence into individual letter.
So I hope to get:
my $var = ['D', '\', 'I', 'K', 'L', 'R', '\', 'L', 'K','/' ,'Q'];
But why this does’nt do it:
my @chars = split(//,$seq);
print Dumper \@chars;
It gave this instead:
my $var = ['D', '\\', 'I', 'K', 'L', 'R', '\\', 'L', 'K', 'Q'];
What is the right way to do it?
What you are getting is exactly what you want.
The way to represent a single
\is'\\'and not'\'as you expected because the\in'\'escapes the second'making the string incomplete but theData::Dumperreturn value can always beevaled as it’s Perl code.But printing the individual elements of the array by say looping over it will print
\.