#!/usr/bin/perl -w use strict; use Data::Dumper; open (FILE,'<', "query63.txt") || die "cannot open query63.txt"; my ($ctf,$df)=(); #pertain to many lines of input, reset occasionally my %query=(); while () { next if /^\s*$/; #skip blank lines my($first_col, $doclen, $tf) = split; if ($tf eq '') #inialization to "new section of numbers" { #when a 2 instead of 3 parameter line $ctf = $first_col; $df = $doclen; next; } push @{$query{$first_col}},{'doclen' => $doclen, 'tf' => $tf, 'df' => $df, 'ctf' => $ctf, }; } sub print_query { my $first_col = shift; print "*First_col = $first_col\n"; if ( !exists($query{$first_col}) ) { print " $first_col does not exit, query failed\n"; return; } #the value of $query{$first_col} is reference to an #anonoymus array of hash references. my $total_records = @{$query{$first_col}}; my $cur_record =1; foreach my $href (@{$query{$first_col}}) { print " Record $cur_record of $total_records\n"; while ( my($key,$value) = each %$href ) { printf " %-10s => %s\n",$key,$value; } $cur_record++; print "\n"; } } print_query (82); print_query (3); print_query (100); #print Dumper \%query; #uncomment to see what this does! __END__ *First_col = 82 Record 1 of 2 ctf => 104353 df => 42122 doclen => 1141 tf => 10 Record 2 of 2 ctf => 904777 df => 82810 doclen => 1141 tf => 30 *First_col = 3 Record 1 of 1 ctf => 904777 df => 82810 doclen => 243 tf => 7 *First_col = 100 100 does not exit, query failed