Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

sarani's scratchpad

by sarani (Sexton)
on May 22, 2006 at 12:16 UTC ( #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;
}
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[atcroft]: stevieb: Sad to say that I only recently learned that particular trick, but I have since found it very useful.... :)
[james28909]: ill be back with a solution eventually
[stevieb]: it's a reminder to re-inforce it :P
[atcroft]: james28909: That particular questions was a bit of trick, actually (depending on the country you are in). More interesting is, if you are trying to subtract from an epoch time, for instance, you might have to consider when/if DST occurs for a location,
[atcroft]: because you may have to adjust the number of seconds you change from an epoch from 86400 (not to mention leap seconds)....
[atcroft]: james28909: Although if your program is using a database, you might be able to "pass the buck" to the database and ask it to do the date change for you....

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2017-04-29 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.