#opening the file for reading open IN,"$fileName" ; #reading the whole file into an array. my @F=; close IN; #reading the last line of the file my $lastLine=$F[$#F]; my $firstLine=$F[0]; #spliting last line by tabs my @line=split /\t/,$lastLine; #spliting first line by tabs my @firstSplitLine=split /\t/,$firstLine; #finding the column number that equals the fieldName my $fieldNum = -1; my $numberOfFields = scalar(@firstSplitLine); for($counter=0 ; $counter < $numberOfFields ; $counter++) { $ourstring = $firstSplitLine[$counter]; $ourstring =~ s/\n\n/\n/g; #=~ s/ \s//g;# HERE IS WHERE I'M TRYING DIFFERENT STUFF... if($fieldName eq $ourstring) # The "problematic" area { $fieldNum=$counter; last; } } # if the field wasn't found if($fieldNum==-1) { print STDERR "\n" if ($permit_writing); print STDERR "The field you asked for was not found, now returning last value: $lastValue\n" if ($permit_writing); print STDERR "\n" if ($permit_writing); return $lastValue; } #printing the required field print STDERR " Value: $line[$fieldNum]\n\n" if ($permit_writing); return $line[$fieldNum];