Convert String Array

[problem]

Converting a string into an array

[/problem]

[solution]

To convert a string to an array, use split.

[/solution]

[example]

Here we have a string, comprising of fields separated by commas.

So we just split on the comma, but this could also be spaces, etc.


$str="one,two,three";
@rr=split ',', $str;
print $#rr."n"; # outputs 2

[/example]

[reference]

[tags], Perl Coding School[/tags]

[/reference]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *