sub getEntries() # This function returns all files from the db folder { if(!(opendir(DH, $config_postsDatabaseFolder))) { die('Error opening '.$config_postsDatabaseFolder.' folder'); } my @entriesFiles = (); # This one has all files names my @entries = (); # This one has the content of all files not splitted foreach(readdir DH) { unless($_ eq '.' or $_ eq '..') { push(@entriesFiles, $_); } } @entriesFiles = sort{$b <=> $a}(@entriesFiles); # Here I order the array in descending order so i show Newest First foreach(@entriesFiles) { my $tempContent = ''; open(FILE, "<$config_postsDatabaseFolder/$_"); while() { $tempContent.=$_; } close FILE; push(@entries, $tempContent); } return @entries; } sub getCategories # This function is to get the categories not repeated in one array { my @categories = ('General'); my @tempCategories = (); if(-d "$config_postsDatabaseFolder") { my @entries = getEntries(); foreach(@entries) { my @finalEntries = split(/"/, $_); push(@tempCategories, $finalEntries[3]); } foreach(@tempCategories) { my $add = 0; my $p = $_; foreach(@categories) { if($_ ne $p) { $add = 1; } else { $add = 0; last; } } if($add == 1) { push(@categories, $p); } } } return @categories; }