id_1=value|id_2=value|id_3=value|..... #### #-------------------------------------------------------# #-------------------------------------------------------# sub get_filecontent { my @temp_data; open (TEMPFILE,"$_[0]"); @temp_data = ; close (TEMPFILE); return( @temp_data ); } #-------------------------------------------------------# #-------------------------------------------------------# sub get_fileRef { my ($fname, $ref_dat) = @_; open (TEMPFILE,"$fname"); @{$ref_dat} = ; close (TEMPFILE); } #### #-- filter my (@new_dat) = (); foreach my $line (@loaded_data) #-- loop thru all data { chomp($line); my (%trec) = &line2rec($line); if ($trec{'active'}) { push(@new_dat, $line); } } (@loaded_data) = (@new_dat); #-- overwrite (@new_dat) = (); #### #---------------------------------------------------# # LINE2REC #---------------------------------------------------# # convert a line into a record by separator | sub line2rec { my ($line) = @_; my (@arr) = split( /\|/, "$line" ); my (%trec) = &hash_array(@arr); return (%trec); } #---------------------------------------------------# #---------------------------------------------------# sub hash_array { my (@arr) = @_; my ($line, $name, $value, $len_name); my (@parts) = (); my (%hashed) = (); foreach $line (@arr) { chomp($line); if ($line =~ /=/) { (@parts) = (); (@parts) = split( /\=/, $line ); #-- just incase got more than one = separator $name = "$parts[0]"; #-- use first element as name $len_name = length($name)+1; $value = substr( "$line", $len_name, length("$line")-$len_name ); #-- !! cannot use join, if last char is separator then will disappear after split $hashed{$name} = $value; } } return (%hashed); }