<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">foldr_tuple(F, A, Tuple) -></div><div class="gmail_default" style="font-family:monospace,monospace">    foldr_tuple_loop(F, A, Tuple, N).</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">foldr_tuple_loop(_, A, _, 0) -></div><div class="gmail_default" style="font-family:monospace,monospace">    A;</div><div class="gmail_default" style="font-family:monospace,monospace">foldr_tuple_loop(F, A, Tuple, K) -></div><div class="gmail_default" style="font-family:monospace,monospace">   foldr_tuple_loop(F, F(A, element(K, Tuple)), Tuple, K-1).</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Stick that in a library somewhere; if you are working with</div><div class="gmail_default" style="font-family:monospace,monospace">variable-length tuples you'll have other uses for it.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">    foldr_tuple(fun (S, L) -></div><div class="gmail_default" style="font-family:monospace,monospace">            [string:len(S), [[C] || C <- S] | L]</div><div class="gmail_default" style="font-family:monospace,monospace">        end, [], Input)</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Of course you can combine tuple_to_list/2 and lists:foldr/3,</div><div class="gmail_default" style="font-family:monospace,monospace">but this avoids creating an intermediate list that you do not</div><div class="gmail_default" style="font-family:monospace,monospace">really want.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">        <br></div><div class="gmail_default" style="font-family:monospace,monospace">         <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 3 Jul 2020 at 21:36, Papa Tana <<a href="mailto:papa.tana101@gmail.com">papa.tana101@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi World,<br>
<br>
I have the below code working very well:<br>
<br>
Input = {"DUMMYAPN", "MNC005", "MCC646", "GPRS"}.<br>
<br>
Static1 = element(1,Input).<br>
Static2 = element(2,Input).<br>
Static3 = element(3,Input).<br>
Static4 = element(4,Input).<br>
<br>
Size1 = string:len(Static1).<br>
Size2 = string:len(Static2).<br>
Size3 = string:len(Static3).<br>
Size4 = string:len(Static4).<br>
<br>
Ret1 = [[X] || X <- Static1].<br>
Ret2 = [[X] || X <- Static2].<br>
Ret3 = [[X] || X <- Static3].<br>
Ret4 = [[X] || X <- Static4].<br>
<br>
VALUE = [Size1, Ret1,Size2, Ret2,Size3, Ret3,Size4, Ret4].<br>
BINARYVALUE = list_to_binary([Size1, Ret1,Size2, Ret2,Size3, Ret3,Size4, Ret4]).<br>
<br>
Expected Result is Ok:<br>
[8,<br>
 ["D","U","M","M","Y","A","P","N"],<br>
 6,<br>
 ["M","N","C","0","0","5"],<br>
 6,<br>
 ["M","C","C","6","4","6"],<br>
 4,<br>
 ["G","P","R","S"]]<br>
<br>
<<8,68,85,77,77,89,65,80,78,<br>
        6,77,78,67,48,48,53,<br>
        6,77,67,67,54,52,54,<br>
        4,71,80,82,83>><br>
<br>
<br>
The problem is that the Input value does not always have the same<br>
format, and changes everytime, for example:<br>
Input = {"TOPON", "S11", "NODE", "EPC", "MNC05", "MCC646",<br>
"3GPPNETWORK", "ORG"}.<br>
<br>
<br>
My problem is:<br>
I am creating N variables each time I receive an Input with Length of N.<br>
I'm sure that there is a more efficient way to work with it, by using<br>
kind of loop or recursion, but I'm stuck a couple of days so far, I<br>
cannot find how to achieve it.<br>
Any advice would be welcome.<br>
<br>
Thanks,<br>
</blockquote></div>