Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Local variable in functions (gawk)

$
0
0
Hi Everybody :)

I need your help, because i know a local variable in a function for example k, it is different of other variable(with the same name k) this a global variable. Is that right?

Code:

dgawk> run
Starting program:
3238860128818202
3 4 7 11 12 13 17 22 23 32 35 37 41 48 49 55 63
Stopping in Rule ...
Breakpoint 1, main() at `deco-int.awk':16
16          parseo_datos();
dgawk> s
parseo_datos() at `deco-int.awk':88
88      k = 1;
dgawk> s
89      inicio = 69;
dgawk> s
90      while (k <= 15) {
dgawk> set k=10
k = 10
dgawk> set inicio=177
inicio = 177
dgawk> p k
k = 10
dgawk> p inicio
inicio = 177
dgawk> s
91            i = campo_enc[k];
dgawk> s
92            data=0;
dgawk> p i
i = "32"
dgawk> s
93            long_data=0;
dgawk> s
94            if (C[i,4] == "F") {
dgawk> s
99            if (C[i,4] == "V") {
dgawk> s
100              long_data = strtonum(quita_ceros(cadhex_to_caddec(substr($0, inicio, C[i,5] * 2))));
dgawk> p C[32,4]
C["324"] = "V"
dgawk> p k
k = 10
dgawk> s
100              long_data = strtonum(quita_ceros(cadhex_to_caddec(substr($0, inicio, C[i,5] * 2))));
dgawk> p k
k = 10
dgawk> n
101              if (long_data <= C[i,6]) {
dgawk> p k
k = 1

the function "quita_ceros", I have it in include file:

Code:

function quita_ceros(cad)
{
 k=1;
 while (k <= length(cad)) {
      if (substr(cad , k , 1) == "0") {
        cad = substr(cad, k + 1, length(cad));
        continue;
        }
      else
          break;
      k++;
    }
 return cad;
}

if you see the debug, the value of variable global change after call the function "quita_ceros", why? both variable have the same name, but a is local variable and other is a variable global.

Thanks for advance.:b:

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images