Re: Regarding file handling Actually my work is from the text file, i need to consider each entry in every structure, and find its data type, to which its typedefed to and then assign the values according to the value of the datatype. For eg: A sample of the text file is shown below: STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T {     STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T protocol_discriminator;     STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id; } STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T; }; STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T {     STACK_CC_SS_COMMON_TYPE_CHANNEL_TYPE_T channel_type;     STACK_CC_SS_COMMON_TYPE_CHANNEL_MODE_T channel_mode; } STACK_CC_SS_COMMON_TYPE_CHANNEL_INFO_T; }; STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T {     STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T protocol_discriminator;     STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id; } STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T; }; >From the above text, i need to read STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T and find to which data type this is type defed to and then asign the values according to the value of the data type. Here the basic data types are UINT8 and UINT16 which would read one and two bytes respectively. All the other data types are type  defed to one of the two. My code in generating the file is as shown: this is just a module from the original code #!/usr/bin/perl use strict; use warnings; $file = "filename"; unless (open(INNER, $file)) {             die("Cannot open file \\n");         } unless (open(INN1, "+>outfile.txt")) {         die("Cannot open file \\n");     }     while ($innergrep = ) {         chop($innergrep);         while((($inn = index ($innergrep, "typedef struct")) >= 0)||(($inn = index ($innergrep, "typedef union")) >= 0)) {             $p = 0;             while($inn = (index ($innergrep, "}")) < 0) {                 $innergrep = ;                 chop($innergrep);                 $innerstore[$p] = $innergrep;                 $p++;             }             if($inn = (index ($innergrep, "$innerB;")) >= 0) {                 $innerlen = @innerstore;                 print INN1 "$innerB\\n";                 for(my $j=0; $j<$p; $j++) {                     print INN1 "$innerstore[$j]\\n";                 }                 print INN1 "};\\n";             }         }     } The above code is just a small module from the original code. In the above code, the file name is passed as an argument and it is stored in $file. From the file which is specified, i need to search for the structure associated with the primitive supplied in $innerB. As in the file the structure is written as STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T {     STACK_CC_SS_COMMON_TYPE_REFERENCE_PROTOCOL_DIS_T protocol_discriminator;     STACK_CC_SS_COMMON_TYPE_REFERENCE_TRANSACTION_ID_T   transaction_id; } STACK_CC_SS_COMMON_TYPE_REFERENCE_ID_T; The primitive name is found only at the end of the structure. So initially read the contents, store it in a array and and then when the primitive name in the structure matched with the primitive name passed here, then i write it to the outfile.txt. As, each time the primitive is passed through some variable, i am unable to check the duplicate copies. That is, if the same primitive is passed again and again, my code just gets the structure and stores it multiple times. I want it to store only once. That is the problem. I hope this describes the problem to all. I kindly request you to guide me in this. Thanks and Regards, Dharshana On 6/22/07, Tom Phoenix  wrote: > > On 6/21/07, Dharshana Eswaran  wrote: > > > I am unable to get the desired result. Its printing all the instances of > the > > block. > > Please post the smallest self-contained example program which other > people can use to see what you're doing, with what data. Ideally, > narrow things down to the one line of code or piece of data that does > something, or fails to do something, as appropriate. (For example, if > you're using the algorithm that Paul Lalli supplied, could two or more > very similar strings cause you mistakenly to think you're seeing > duplicate output?) > > Good luck with it! > > --Tom Phoenix > Stonehenge Perl Training >