in reply to Re: sorting hash alphabetically with numbering
in thread sorting hash alphabetically with numbering

Yes, exactly. Thank you!

It works perfectly, but I don't quite follow this line...

printf "%d: %s, %s\n", ++$n, $_, $cities{ $_ } for @sorted;

Replies are listed 'Best First'.
Re^3: sorting hash alphabetically with numbering
by kcott (Archbishop) on Oct 12, 2015 at 04:07 UTC

    printf takes a FORMAT: in this case, that's "%d: %s, %s\n". Those FORMATs are documented under the related function sprintf.

    The 'for @sorted' part is a statement modifier: documented under perlsyn: Statement Modifiers.

    Hopefully, the remaining parts are clear. If not, please specify what part(s) you're having difficulty with.

    — Ken