in reply to Re^2: create a matrix for print 0 or 1 from pairing
in thread create a matrix for print 0 or 1 from pairing
I have tried using that as per suggestions by Perlbotics /p>
#use strict; use warnings; my %A = (horse=> 'a',lion=>'b' ,mule=>'c',tiger =>'d'); my @order= sort keys %A; while (<DATA>) { warn("Line $.: cannot understand: $_") , next unless /(\w+);(\w+)/; my ($row, $col) = ($1,$2); $A {$row}{$col}++; $A{$col}{$row}++; } # print col. header print " "; printf(" %2s",$_) for (@order); print "\n"; #print matrix A for my $row (@order) { printf(" %2s", $row); for my $col (@order) { printf(" %3d", exists $A{$row}{$col} ? "1" : "0" ); } print "\n"; } __DATA__ horse;tiger lion;mule lion;tiger horse;mule
However If u see in the code i have not use strict command; if using strict command in the first line error displayed will be Can't use string ("a") as a HASH ref while "strict refs" in use at work_matrix.pl line 12, <DATA> line 1. What can be possible solution if using strict command?I have got ouput horse lion mule tiger horse 0 0 1 1 lion 0 0 1 1 mule 1 1 0 0 tiger 1 1 0 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: create a matrix for print 0 or 1 from pairing
by jakobi (Pilgrim) on Oct 29, 2009 at 09:48 UTC |