Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8360857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:33:50+00:00 2026-06-09T11:33:50+00:00

this is my data nodes x y z 1112, 23, 56, 88 2223, 56,

  • 0

this is my data

nodes             x             y         z

1112,         23,       56,       88
2223,         56,       78,       54
3345,         32,       12,       11
4321,         11,       10,       06
5234,         10,       10,       12
6123,         12,       06,       04

now i want those nodes which are nearest to each other..example:
if distance between node(1112) and node(4321) is smaller (let d=10) than the distance between node(1112) and node(3345) (let d=34) and vice versa than output should be=

     node:1112 and node:4321 are closest
     node:6123 and node:3345 are closest.....

i am using distance formula like this:
my $dist = sqrt( ($x-$x2)*2 + ($y-$y2)*2 + ($z-$z2)**2 );

 i.e:
 d=sqrt( (56-23)**2 + (78-56)**2 + (54-88)**2 )
 d=sqrt( (32-23)**2 + (12-56)**2 + (11-88)**2 )
 d=sqrt( (11-23)**2 + (10-56)**2 + (06-88)**2 )
 d=sqrt( (10-23)**2 + (10-56)**2 + (12-88)**2 )....and so on

similarly for other nodes and their coordinates

 d=sqrt( (23-56)**2 + (56-78)**2 + (88-54)**2 )
 d=sqrt( (32-56)**2 + (12-78)**2 + (11-54)**2 )
 d=sqrt( (11-56)**2 + (10-78)**2 + (06-54)**2 )
 d=sqrt( (10-56)**2 + (10-78)**2 + (12-54)**2 )....

i have done this but got nothing……

use strict;
use warnings;
use Data::Dumper;

open(IN , "<" , "1.txt");
#open(OUT , ">" , "out.txt");

my $node_flag=0;
my %node_hash_1;
my %node_hash_2;

my @node_1;
my @node_2;

my @distance_array;
my $i=0;

foreach my $line(<IN>)
{
    if($line=~/^\*node$/i)
    {
        $node_flag=1;
        next;
    }
    if($node_flag==1)
    {
        if($line!~/^\*\*/i)
        {
            my @array=split(",",$line); # or  my @array=(split(",",$line))[1,2,3]
            my $node_id=shift @array;
            $node_hash_1{$node_id}=\@array;

            push(@node_1,[@array]);
            push(@node_2,[@array]);

            foreach my $var1(@node_1)
            {
                my($x,$y,$z)=@{$var1};
                foreach my $var2(@node_2)
                {
                    my($x2,$y2,$z2)=@{$var2};
                    my $dist = sqrt( ($x-$x2)**2 + ($y-$y2)**2 + ($z-$z2)**2 );
#                   print $dist;
                    print"\n";
                    foreach my $value(@{$node_hash_1{$node_id}})
                    {
                        my $vars=join",",@{$node_hash_1{$node_id}};
                        my @arr=split ",",$vars;
#                       print $arr[0];
                        print $vars;
                        if ($x==$value && $y==$value && $z==$value)
                        {
                            push @{$node_hash_1{$node_id}},$dist;
#                           $node_hash_2{x} = $x;
#                           $node_hash_2{y} = $y;
#                           $node_hash_2{z} = $z;
                        }
                    }
                }
            }
        }
        else
        {
            $node_flag=0;
        }
    }
}
#print Dumper(\%node_hash);
#print Dumper(\@distance_array);
#print Dumper(\@node_1);
#print Dumper(\%node_hash_2);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:33:52+00:00Added an answer on June 9, 2026 at 11:33 am
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my (@data, @temp, @result);
    
    sub calc {
        my ($a, $b) = @_;
        my $dat = 0;
        $dat += ($a->[$_] - $b->[$_]) ** 2 for (1..3);
        return sqrt $dat;
    }
    
    while (<DATA>) {
        push @data, [split /,?\s+/];
    }
    
    for my $x (@data) {
        for my $y (@data) {
            push @temp, [calc($x, $y), $x, $y] if ($x->[0] > $y->[0]);
        }
    }
    
    @result = sort { $a->[0] <=> $b->[0]; } @temp;
    
    for (@result) {
        print "[", join(', ', @{$_->[1]}), "], [", join(', ', @{$_->[2]}),
            "] => $_->[0]\n";
    }
    
    __DATA__
    1112,         23,       56,       88
    2223,         56,       78,       54
    3345,         32,       12,       11
    4321,         11,       10,       06
    5234,         10,       10,       12
    6123,         12,       06,       04
    

    output:

    [6123, 12, 06, 04], [4321, 11, 10, 06] => 4.58257569495584
    [5234, 10, 10, 12], [4321, 11, 10, 06] => 6.08276253029822
    [6123, 12, 06, 04], [5234, 10, 10, 12] => 9.16515138991168
    [4321, 11, 10, 06], [3345, 32, 12, 11] => 21.6794833886788
    [6123, 12, 06, 04], [3345, 32, 12, 11] => 22.0227155455452
    [5234, 10, 10, 12], [3345, 32, 12, 11] => 22.113344387496
    [2223, 56, 78, 54], [1112, 23, 56, 88] => 52.2398315464359
    [3345, 32, 12, 11], [2223, 56, 78, 54] => 82.3468275041607
    [3345, 32, 12, 11], [1112, 23, 56, 88] => 89.1403387922662
    [5234, 10, 10, 12], [1112, 23, 56, 88] => 89.7830719011106
    [5234, 10, 10, 12], [2223, 56, 78, 54] => 92.217135067188
    [4321, 11, 10, 06], [2223, 56, 78, 54] => 94.62029380635
    [4321, 11, 10, 06], [1112, 23, 56, 88] => 94.7839648885823
    [6123, 12, 06, 04], [2223, 56, 78, 54] => 98.0815986819138
    [6123, 12, 06, 04], [1112, 23, 56, 88] => 98.3717439105356
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i Want to fetch this data using json decode. Please Help.. So far i
I'm rendering data with d3. I have a nodes list from which I construct
I have the following data set, which represents nodes in a directed graph. CREATE
I have this code for BinaryTree creation and traversal class Node { Integer data;
I have a data object that looks like this: { 'node-16': { 'tags': ['cuda'],
I have an array of System.Xml.XmlNode with data similar to this: [0] = <Node1
This data is for a holiday cottage's simple accommodation calendars. The data is simple
I have this data in cell A1: Majestic Properties Design District, LLC, Ste. 101,
If user insert this data 16 HOUSEHOLD STAND FAN AA070021A the output should be
I need to make this data variable global: $.ajax({ url: get_data.php, cache: false, dataType:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.