Hi again monkers! I have another question, im triying to discover if the exists function or the defined should be enought for do that, but im shure, take a look:
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; } }
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:
(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; }
Perl told me in the line
$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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.