There's more than one way to do things | |
PerlMonks |
sarani's scratchpadby sarani (Sexton) |
on May 22, 2006 at 12:16 UTC ( [id://550916]=scratchpad: print w/replies, xml ) | Need Help?? |
#! /root/bin/perl use strict; use warnings; use subs; sub square; sub read; sub dist; my $r; my $r2; my $xh; my $yh; my $zh; my $f1; my $FILE1; my $hline; my @hlines; $f1=&read; my $x1; my $y1; my $z1; my $f2; my $FILE2; my $pline; my @plines; $f2=&read; open (FILE1, "$f1") or die "Argh! File not opened! $!"; open (FILE2, "$f2") or die "Argh! Second file not opened! $!"; while (<FILE1>) { $hline=<FILE1>; push (@hlines,$hline); } while (<FILE2>) { $pline=<FILE2>; push (@plines,$pline); } close FILE2; close FILE1; print @hlines; print @plines; &dist; exit; sub dist { foreach $hline (@hlines) { $xh= substr $hline,31,8; $yh= substr $hline,40,8; $zh= substr $hline,48,8; foreach $pline (@plines) { print '"',$pline,'": len=',length($pline),"\n"; $x1= substr $pline,31,8; $y1= substr $pline,40,8; $z1= substr $pline,48,8; $r2=((&square($xh-$x1))+(&square($yh-$y1))+(&square($zh-$z1))); $r=sqrt($r2); print "$r2 and square root is $r\n"; if(($r<=2.4)&&($r>=3.6)) { print "match!"} } } print $i; return 1; } sub square { my $num; my $sq; $num=shift; $sq = $num * $num; return $sq; } sub read { print "Enter file name:"; $a=<STDIN>; chomp($a); return $a; } |
|