I have a cgi script that takes in several values as parameters and reads a text file into an array. It then greps the array for each value that has been passed in to see if that value already exists in the array (and by association the text file). What I would like to do is that if a given value already exists in the array to replace that element with the newer one (that has been passed in) so that at the end of the script I can rewrite the array to the text file, and that file will have all the newest values.
The easiest way I can think to do this would be that if I could get grep to return the element ID in the array I could simply set the @array[$ID] = to the new value. But I can't seem to find out how to get it to return the element ID while parsing the array. Any help would be greatly appreciated. Thanks.
PS. The format of the data is a combination of alphanumeric characters, followed by -- one to four numbers -- another one to four numbers. For example: mpd11--190--91. I'm only matching the first set and it's the two sets of numbers I'm interested in updating.