Assign multiple variables from a split list on the fly
Posted: Wed Oct 09, 2019 9:41 am
I can assign multiple new variables from a split list on the fly in Perl in one line of code:
In LiveCode, it takes multiple lines (the number of variables plus one):
I'd like a Perl-like way to assign multiple variables in one line of code, in keeping with LiveCode's marketing idea of "less code".
I know I can use arrays, but I'm not asking about arrays, I'm asking about regular variables.
Thank you.
[Edited to correct that LC arrays start at 1, not 0.]
Code: Select all
$data = 'Dave,46,sr. engineer,colorado,23';
($name, $age, $title, $city, $code) = split(',',$data);
Code: Select all
put 'Dave,46,sr. engineer,colorado,23' into data
split data by comma
put data[1] into theName
put data[2] into age
put data[3] into title
put data[4] into city
put data[5] into theCode
I know I can use arrays, but I'm not asking about arrays, I'm asking about regular variables.
Thank you.
[Edited to correct that LC arrays start at 1, not 0.]