Dijkstra Algorithm in perl