# Assigning a string to variables names

I have the list

n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv\"}}.


That is {{variable name, string}, {name, string}}. I want the variable REL1 to be set to "REL.csv". How can I do that?

n1[1,1]] = n1[1,2]] does not work.

• If you want each name Set to the associated string use Set @@@ n1 Apr 9, 2020 at 21:25

Still another approach is

Clear[REL1, RAND1, n1];
n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}};
Set @@ First[n1];


which yields

{REL1, RAND1}
(* {"REL.csv", RAND1} *)


as expected. To perform this process on the whole list, use

Clear[REL1, RAND1, n1];
n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}};
Set @@@ n1;


which yields

{REL1, RAND1}
(* {"REL.csv", "RAND.csv"} *)


You can do this using replacements by replacing List with Set. For example:

n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}};
Evaluate[n1[[1]] /. List -> Set]


Now REL1 is REL.csv

You can do a whole list of such things:

Clear[REL1, RAND1];
n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}};
Table[Evaluate[n1[[i]]] /. List -> Set, {i, Length[n1]}]

ClearAll[REL1, RAND1];
n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}};
(Evaluate@First@# = Last@#) & /@ n1;
{REL1, RAND1}
(* {"REL.csv", "RAND.csv"} *)


Applying set at level 1

n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}};

(#1 = #2) & @@@ n1;

{REL1, RAND1}

{"REL.csv", "RAND.csv"}