Convert String Array

Problem

Converting a string into an array



Solution

To convert a string to an array, use split.



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



Reference

[tags], Perl Coding School[/tags]



Leave a Reply

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