Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: array comparisons

by McA (Priest)
on Oct 27, 2014 at 16:06 UTC ( [id://1105176]=note: print w/replies, xml ) Need Help??


in reply to array comparisons

Hi,

hopefully this helps to get your mind around your problem:

#!/usr/bin/perl use strict; use warnings; use 5.010; use Data::Dumper; my %neigbours; while (my $line = <DATA>) { chomp $line; my ($id_pathway, @pathnodes) = split ' ', $line; my $path_length = @pathnodes; if($path_length < 2) { warn "Don't know whether paths with less than two nodes are al +lowed. Skipping."; next; } for (my $i = 0; $i < $path_length - 1; $i++) { my $key = "$pathnodes[$i]$pathnodes[$i+1]"; if(defined $neigbours{$key}) { if($neigbours{$key}->{'minpathlen'} >= $path_length) { $neigbours{$key}->{'minpathlen'} = $path_length; $neigbours{$key}->{'id_pathway'} = $id_pathway; } } else { $neigbours{$key}->{'minpathlen'} = $path_length; $neigbours{$key}->{'id_pathway'} = $id_pathway; } } } say Dumper(\%neigbours); __DATA__ A a b c d e f B a b c

Allow me an annotation: Please use meaningful variable names. Your code is hard to read.

Regards
McA

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1105176]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-04-23 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found