1. You wrote:
"It's neither easy nor works for its intended purpose. You've hard-coded the values in. The whole point of the Perl one-liner is to split up some string (which will not always have the same value!) and assign it to different unique variables on the fly. How are you not understanding this?"
and:
"Split a string and assign it to variables on the fly in one line, a là Perl: ($name, $age, $title, $city, $code) = split(',',$data);
Status: No solution. Could put the split string into arrays, but not into variables."
Hard coded values: Your two lines of perl code
Code: Select all
$data = 'Dave,46,sr. engineer,colorado,23';
($name, $age, $title, $city, $code) = split(',',$data);
have two hard coded lists as input and use split.
To make the strings variable (use 'on the fly') you have to write a function/repeat, just as in LC.
As you don't want to use split in LC you could (as essentially already written) do the same similarly simple as follows.
(Name your fields exactly as the variables (for simplicity) and add a field "tNew")
Code: Select all
local tN="tName,tAge,tTitle,tCity,tCode" -- names of flds and variables
on action
repeat for each item I in tN
do "put fld I into " & I --> assigns values to variables <--
end repeat
-- use the variables, example: output their values, avoiding comma
repeat for each item I in tN
put cr & "• " & I & " is " & value(I) after output
end repeat
put char 2 to -1 of output
-- put tName --> use directly their names works also
end action
on mouseUp -- example usage
if "tNew" is not among the items of tN
then put ",tNew" after tN -- change tN after adding the fld "tNew"
action
end mouseUp
10 lines of code (local and action) that solve both of your initial questions and also your additional delimiter problem.
And it has no hard coded input but tN. You simply have to add fields and increase tN (you could do that by script). It just works, everybody can test it.
2. You wrote: "I never tried to separate values with bar lines." That wasn't addressed to you.
3. The first two of my examples
Code: Select all
put "variable1,variable2,variable3" into theList -- the string of items
put "variable1","variable2","variable3" into theList -- items of strings
put (variable1,variable2,variable3) -- items of variable values
are not broken (as you wrote), they simply serve as different examples of how to create a list.
They create a string containing literal (sub-)strings as items (the third a string containing variable values as items). What doesn't work with them for you?
4. Space delimiters for parameters:
I have to correct my answer, sorry. You are right: LC is accepting space as parameter separator in the definition of a handler or a function (of course not in the call of the handler/function).
===
By the way. I like perl and use it for some special jobs by LC's shell(). Did you ever try to do that?