On Thu, 10 Jan 2013 17:01:43 +0700 budi perl <budipe...@gmail.com> wrote:
> Hi, > > I have this following hash: > > #!/usr/bin/perl > # > use strict; > use Data::Dumper; > > my %MYROUTES = ( > "ROUTE-252" => { > # src => dest > 427 => "ABEP", > "ABEP" => 441, > 441 => 427, > 427 => 444, > 444 => "MGWQ", > "MGWQ" => "CDEF" > }, You can't have the same hash key twice; you've duplicated 427 there. Also, you don't need to quote the left side of a fat comma, so you can just as easily say e.g. ABEP => 441. > Expected results: > > ROUTE-252: 427 - ABEP - 441 - 427 - 444 - MGWQ - CDEF > ROUTE-432: Error: can not follow the route! [...] > Can someone shed some light how to find head then follow the path > as above? Many thanks. What have you tried so far? What have you got stuck on? How do you know where the start of the route is? (Rememeber, hash keys will come back in essentially random order; so, where do you start?) If you need to start following from the first key you defined, you'll need to either have an arrayref of hashrefs to iterate over, or store the starting point as well as the routes. -- David Precious ("bigpresh") <dav...@preshweb.co.uk> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/