Dynamic variable assignment by recursion or loop?

Papa Tana papa.tana101@REDACTED
Fri Jul 3 11:36:06 CEST 2020

Hi World,

I have the below code working very well:

Input = {"DUMMYAPN", "MNC005", "MCC646", "GPRS"}.

Static1 = element(1,Input).
Static2 = element(2,Input).
Static3 = element(3,Input).
Static4 = element(4,Input).

Size1 = string:len(Static1).
Size2 = string:len(Static2).
Size3 = string:len(Static3).
Size4 = string:len(Static4).

Ret1 = [[X] || X <- Static1].
Ret2 = [[X] || X <- Static2].
Ret3 = [[X] || X <- Static3].
Ret4 = [[X] || X <- Static4].

VALUE = [Size1, Ret1,Size2, Ret2,Size3, Ret3,Size4, Ret4].
BINARYVALUE = list_to_binary([Size1, Ret1,Size2, Ret2,Size3, Ret3,Size4, Ret4]).

Expected Result is Ok:


The problem is that the Input value does not always have the same
format, and changes everytime, for example:
Input = {"TOPON", "S11", "NODE", "EPC", "MNC05", "MCC646",

My problem is:
I am creating N variables each time I receive an Input with Length of N.
I'm sure that there is a more efficient way to work with it, by using
kind of loop or recursion, but I'm stuck a couple of days so far, I
cannot find how to achieve it.
Any advice would be welcome.


More information about the erlang-questions mailing list