Hi punit jain, Please check my comments below.
On Tue, Jan 8, 2013 at 1:28 PM, punit jain <contactpunitj...@gmail.com>wrote: > Hi , > > I have a file as below : - > > { > test = ("test123"); > test = ("test123","abc"); > test = ("test123","abc","xyz"); > } > { > test1 = ("passfile"); > test1 = ("passfile","pasfile1"); > test1 = ("passfile","pasfile1","user"); > } > > and so on .... > > The requirement is to have the file parsing so that final output is :- > > test = ("test123","abc","xyz"); > test1 = ("passfile","pasfile1","user"); > > So basically only pick the lines with maximum number of options for each > type. > > Regards. > I basically agreed with Jim on this: Jim >> to learn programming will be to attempt writing a program to accomplish your task, Jim >> then post your program if you have trouble getting it to do what you want. However, if I may suggest using hash, if the lines with the maximum number of options for each type *is the last one in each case*. Since, *hash will only permit only one key*. So, splitting each line on "=", one can take key and value for hash. So, based on the data presented, one can write like so: use warnings; use strict; my %collection_hash; while (<DATA>) { chomp; if (/=/) { my ( $key, $value ) = split /=/, $_, 2; $collection_hash{$key} = $value; } } print $_, ' = ', $collection_hash{$_}, $/ for sort keys %collection_hash; __DATA__ { test = ("test123"); test = ("test123","abc"); test = ("test123","abc","xyz"); } { test1 = ("passfile"); test1 = ("passfile","pasfile1"); test1 = ("passfile","pasfile1","user"); } *OUTPUT:* test = ("test123","abc","xyz"); test1 = ("passfile","pasfile1","user"); Please, *NOTE* that this will only work as you want if the last line in each case has the maximum options, this is what the data you showed here presented. -- Tim