#!/usr/bin/perl use strict; my (%hash,$hash_id); my $isa_array_ref; open(my $fh,"<",$ARGV[0]) || die "$0: can't open $ARGV[0] for reading: $!"; LINE: while(<$fh>){ chomp($_); next LINE if ($_ eq "Term"); #split on first blank space my @TermRow = split(/ /,$_,2); if($TermRow[0] eq 'id:'){ $hash_id = $TermRow[1]; $isa_array_ref = undef; } elsif($TermRow[0] eq 'is_a:'){ my @TermISAText = split(/!/,$TermRow[1]); #checking if anonymous array reference already exists if($isa_array_ref){ my @temp_array = @{$isa_array_ref}; push(@temp_array,$TermISAText[1]); $isa_array_ref = \@temp_array; $hash{$hash_id} = $isa_array_ref; } else{ #creating an anonymous array reference $isa_array_ref= [$TermISAText[1]]; $hash{$hash_id} = $isa_array_ref; } } } close($fh); print "Result of Extraction:\n "; my @id_keys = keys %hash; foreach(@id_keys){ print "key : $_"; print "list of values \n"; foreach(@{$hash{$_}}){ print $_,"\n"; } print "\n"; } #### XXXXXX:progs$ perl term_reader.pl ./term.txt Result of Extraction: key : HP:0000008list of values Abnormal internal genitalia Abnormality of the female genitalia key : HP:0000007list of values Mode of inheritance