# Now after reading the user inputs for updating the file as follow my @updateInfo; my @updateInfo = "$inputONE\t$inputTwo\t$inputThree"; if ( $currentData{$line} ) { print "the info exists already\n"; exit; +} else { print " your info is being saved and the file is updated\n"; ex +it;

Now, $inputONE is undefined, so it stringifies as an empty string: ''. Same with $inputTwo and $inputThree.

It might be better to format the three variable names in corresponding styles. $inputONE has the differentiating number parrt in ALL CAPS, while the other two just capitalize the first letter of the numeric portion.

If you ever have variables with numbers in the name, this is a red flag that you should probably be using an array. It is no problem that you use elements 1, 2 & 3 ...after all, it is so common to deal with the 'first' element being in slot zero. Alternately, you can simply ignore array slot zero, if 1, 2 & 3 are important to you.

Mind you, are you locked on three elements? Can it change? All the more reason to use an array.

If the number of elements might change, you don't want to get stuck hard coding the value you assign to @updataInfo. join() is your friend.

@updateInfo = join( "\t", @inputs );

So that sets $updateInfo[0]. What were you planning to put in $updateInfo[1], $updateInfo[2], etc.? So maybe it should by $updateInfo instead of @updateInfo.

Of course, the final step is testing whether the update info is already present in the array:

if ( $currentData{$updateInfo} ) { ......

PostScript: I don't find Data or Info very meaningful words to use in variable names. After all, every variable contains data and info. Od course, this is just a test snippet, so it's hard to come up with meaningful names.

--
TTTATCGGTCGTTATATAGATGTTTGCA


In reply to Re: Hash problem by TomDLux
in thread Hash problem by Anonymous Monk

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.