in reply to how to get the matrix in output?

use Data::Dumper; might give you a clearer picture of whatever data structure you are working with. For example:
print Dumper(\@sim);

However, I do not believe the code you posted is the actual code that you are using. The code you posted would not compile without errors since you have not declared several variables with my, such as @words and @sim.

It is also a good practice to check the success of open, for example:

open my $in_fh, '<', $Infile or die "Can not open file $Infile: !$\n"

Replies are listed 'Best First'.
Re^2: how to get the matrix in output?
by smilly (Novice) on Feb 06, 2008 at 11:21 UTC
    Dear Friend, U were right, I re arranged my codes but I sent the older version to you. It's my newer version of my codes. I followed your advice and i could get the matrix but i dont know why all values are "undef". any idea?
    #! /usr/local/bin/perl -w use strict; use warnings; use WordNet::QueryData; use WordNet::Similarity::random; use WordNet::Similarity::path; use WordNet::Similarity::wup; use WordNet::Similarity::lch; use WordNet::Similarity::jcn; use WordNet::Similarity::res; use WordNet::Similarity::lin; use WordNet::Similarity::hso; use WordNet::Similarity::lesk; use WordNet::Similarity::vector; use WordNet::Similarity::vector_pairs; use Data::Dumper; my $Infile = shift; my $Outfile = shift; my $Measure = shift; my (@sim , $simi); unless (defined $Infile and defined $Outfile and defined $Measure) { print STDERR "Undefined input\n"; print STDERR "Usage: simmat.pl inputfile outputfile measure()\n"; exit 1; } print STDERR "Loading WordNet... "; my $wn = WordNet::QueryData->new; die "Unable to create WordNet object.\n" if(!$wn); print STDERR "done.\n"; open (INPUT, "$Infile") || die "can't open the input file"; my @words = <INPUT>; close (INPUT) ; for my $i (0 .. $#words) { for my $j ( ($i+1) .. $#words) { $sim[$i][$j] = similarity( $words[$i], $words[$j]); $sim[$j][$i] = $sim[$i][$j]; } } sub similarity { my ( $w1, $w2 ) = @_; $simi = 1; my $obj = $Measure -> new($wn); my $simi = $obj-> getRelatedness("$w1#n#1", "$w2#n#1"); return $simi; } open (OUTPUT, ">$Outfile"); print OUTPUT Dumper(\@sim); close(OUTPUT);