Perl string to character array conversion

Below is an example code that will split a string into an array of char[] like C/C++ or other language. There is no built in function in Perl to do such task. Hope below example will helpful for many people.

## String to convert into char array
my $str = "my name is deadman";

## Spliting the string with no delimeter.
my @char_array = split(//,"$str");

foreach my $char (@char_array){
   print $char . "\n"
}

Comments

What do you mean "not built in"? That looks pretty built in to me!

Also, it's a rare operation, because after all, the regex stuff wants strings, not chars. Not much of Perl deals with chars.
Demon said…
The split function is of course a built in function of Perl. But not like in Java toCharArray() that only converts string into a char[].
Demon said…
Here is another post perl-convert-character-array-to-string. If anyone requires, can take a look.