Zhenhai Duan wrote: > Hi, > > I have a simple code but I just cannot get the correct result. Can > anyone take a look at the code for me? Many thanks. > > print "\nOutput: AS -- Subnets\n"; > foreach $key (sort numerically (keys %subnets)) { > print "key = $key", "\n"; > @subnet = split(/:/, $subnets{$key}); > for ($i = 0; $i <= $#subnet; $i++) { > print$subnet[$i], "\n"; > } > } > > foreach $key ( sort numerically ( keys %subnets)) { > printf outfile "%d\t->\t%s\n", $key, $subnets{$key}; > }
I modified only the subroutine numerically to be {$a <=> $b } I also made the data by doing: my %subnets = qw(1 1:4 4 4:1 80 80:); I added a use strict and warnings which required minor changes to add my to your variables. Output came out as you desired ( see below). I am running AS 5.8.3 build 809. Wags ;) ===================================================================== Output: AS -- Subnets key = 1 1 4 key = 4 4 1 key = 80 80 1 -> 1:4 4 -> 4:1 80 -> 80: > > THe output on STDOUT is: > > Output: AS -- Subnets > key = 1 > 1 > 4 > key = 4 > 4 > 1 > key = 80 > 80 > > ANd it is correct. However the results in the output file (outfile) > is: > >> 4 -> 1 >> 1 -> 4 > 80 -> 80 > > Actually I would expect: > > 1 -> 1:4 > 4 -> 4:1 > 80: -> 80 > > (I am using Net::Netmask module, and the perl version is: > > This is perl, v5.8.3 built for i386-linux-thread-multi > > ) > Many thanks for the help, > -Zhenhai ******************************************************* This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ******************************************************* -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>