In perl, you can represent the graph using hash like this:
use warnings;
use strict;
my %graph;
sub add_edge {
my ($n1, $n2) = @_;
$graph{$n1}{$n2} = 1;
$graph{$n2}{$n1} = 1;
}
sub show_edges {
foreach my $n1 (keys %graph) {
foreach my $n2 (keys %{$graph{$n1}}) {
print "$n1 <-> $n2\n";
}
}
}
while (<>) {
my ($n1, $n2) = split /\s+/;
add_edge($n1, $n2);
}
show_edges();
Run it like this:
perl script.pl input.txt
For the shortest path you'll have to decide the start and end node that you want to search the shortest path for.
For this you can use Dijkstra's algorithm. In a nutshell this is how the algorithm works:
Let's call the start node A and the end node B.
Assume that we already know the shortest path for going from A to B. If we are at B, then backtracking our steps using the cheapest path should bring us back to point A. Dijkstra's algorithm starts at A and records the cost of path for going to all of A's adjacent nodes, and repeats the process for each of the adjacent nodes. Once done, then we can print the shortest path from A to B by backtracking from B to A.
To get the number of nodes: print keys %graph;
To get the number of edges you'll have to count (uniquely) the number of entries in each of the hash elements, for example to count the number of edges for one node: print keys %{$graph{'ATF-1'}};