in reply to Hash problem
# 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
|
|---|