As you can see in the code, im opening a file that contains the next data: name of something,01*,03*,04* This numbers will change and every hash key (entidad, agrupacion and operativa) its an array that should contains this numbers. Well, im triying to before i push the value readed from the file, check if this exists in his array. Im triying to do that because this numbers refers to something, like a code. And if i read 3 lines where the firsts lines begins for Company,01.... it will push me the value 01 every time it found it. I want to check if exists, if yes, dont push, if no, push to the array (to have only one time every different code). Im triying with exists using the variable to check if this variable exists in the array....but i think the only way if to cycle throught every array with values, checking if this exists, and if dont, push it. I think should be a "more cpu-cycle economy" way to do.. Thanks! Updated: An also, how i may know in a unknown array in a hash (like %hash{$key1}@array{$key2}) which its the last element of the array (not wich its the value, only the position like [0] or 1 or 23) to do something like push @{$hash{$key1}$lastarray-item_plus1{$key2}}. updated again: After i did it, when i do the next:while (<FICHEROCFG>) { $datos_cfg = $_; ($var1,$var2,$var3,$var4) = split (",", $datos_cfg); if ( $db{$var1}{'Entidad'}[$var2]) { push @{ $db{$var1}{'Entidad'} }, $var2; } elsif (exists $db{$var1}{'Agrupacion'}[$var3]) { push @{ $db{$var1}{'Agrupacion'} }, $var3; } elsif (exists $db{$var1}{'Operativa'}[$var4]) { push @{ $db{$var1}{'Operativa'} }, $var4; } }
Perl told me in the line(line 1)->open (FICHEROCFG, "<$fichero_cfg") or die "No se puede abrir + el fichero de configuracion de transacciones $fichero_cfg!!\n"; while ($linea=<FICHEROCFG>) { ($var1,$var2,$var3,$var4) = split (",", $linea); $indice = $#{$db{$var1}} + 1; $db{$var1}{'counter'} = ''; $db{$var1}[$indice]{'Entidad'} = $var2; $db{$var1}[$indice]{'Agrupacion'} = $var3; $db{$var1}[$indice]{'Transaccion'} = $var4; }
$db{$var1}{'counter'} = ''; is: "Not a HASH reference at line 39, <FICHEROCFG> line 1.
Did anyone knows why?
Thanks again!
In reply to Check if value exists into an array in a hash by Sombrerero_loco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |