Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Always, the matching is done with set of three. I am really getting confused with the loops as I never tried programming before. Coming to hash, I require that for further use. If anyone can help me out, it would be appreciated. I am pasting my code below (I know it looks silly but I am learning to do well by using this site) Thank you in advance.10 to 1, 20 to 2, 30 to 3 10 to 2, 20, to 3, 30 to 4 20 to 1, 30 to 3, 40 to 4 20 to 2, 30 to 3, 40 to 4
#!/usr/bin/perl use warnings; use strict; my $filename = "first.txt"; my (@queryx, @queryy, @basex, @basey, %hash, $i, $j, $k, $ss); open (FILE, $filename) or die "can't open $filename: $!\n"; while(<FILE>) { if ($_ =~ /(\S+)\s+(\S+)/) { $hash{$1} = $2; push(@queryx,$1); push (@queryy, $2); } } close(FILE); my $filename1 = "second.txt"; open (FILE1, $filename1) or die "can't open $filename: $!\n"; while(<FILE1>) { if ($_ =~ /(\S+)\s+(\S+)/) { $hash{$1} = $2; push(@basex,$1); push (@basey, $2); } } close(FILE1); $ss = @basex; print $ss, "\n"; print "Enter the Threshold Value: \n"; $j= <STDIN>; open(FILEHANDLE, ">result.cmp") or die "cannot open file for reading: +$!";#Creates an output file $k = 0; print $k, "\n"; my $a1 = $queryx[0]; my $a2 = $queryx[1]; my $a3 = $queryx[2]; while ($i <= $ss) { my $b1 = $basex[$i]; my $b2 = $basex[$i+1]; my $b3 = $basex[$i+2]; my $rr1 = (($a1) - ($b1)); my $rr2 = (($a2) - ($b2)); my $rr3 = (($a3) - ($b3)); my $r1 = sprintf "%.3f", (abs($rr1)); my $r2 = sprintf "%.3f", (abs($rr2)); my $r3 = sprintf "%.3f", (abs($rr3)); if (($r1 <= $j) && ($r2 <= $j) && ($r3 <= $j)) { my $r_sq1 = $r1 * $r1; my $r_sq2 = $r2 * $r2; my $r_sq3 = $r3 * $r3; my $rsum = ($r_sq1 + $r_sq2 + $r_sq3); #print FILEHANDLE "$a1\t$aa1\n"; print FILEHANDLE "$a1\t$a2\t$a3\t$r1\t$r2\t$r3\n"; } if ($k == $#queryx) { exit; } if ($i == $ss) { $k = $k + 1; $a1 = $queryx[$k]; $a2 = $queryx[$k+1]; $a3 = $queryx[$k+2]; print "$a1\t$a2\t$a3\n"; next; } $i++; } close (FILEHANDLE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can any one help me with my query
by tlm (Prior) on Jun 21, 2005 at 13:14 UTC | |
|
Re: Can any one help me with my query
by anonymized user 468275 (Curate) on Jun 21, 2005 at 12:36 UTC | |
by Anonymous Monk on Jun 21, 2005 at 12:48 UTC |