http://www.perlmonks.org?node_id=974056


in reply to Re^3: alphabet counting
in thread alphabet counting

Hmm...

my %h = ( a => 1, b => 2, c => 3 ); print "$k => $h{$k}\n" for my $k (sort keys %h);

Output:

syntax error at D:\progs\perl\junk.pl line 5, near "$k (" Execution of D:\progs\perl\junk.pl aborted due to compilation errors.

Maybe you meant something like:

print "$_ => $h{$_}\n" for sort keys %h;

Or the (no doubt) more newbie-friendly:

for my $k ( sort keys %h ) { print "$k => $h{$k}\n"; };

Replies are listed 'Best First'.
Re^5: alphabet counting
by sauoq (Abbot) on Jun 02, 2012 at 22:32 UTC

    ++ seven hours and several upvotes later. It's amazing how few people are trying around here these days.

    -sauoq
    "My two cents aren't worth a dime.";
      . It's amazing how few people are trying around here these days.

      S'always slow on Saturdays.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?