in reply to Transforming a for loop to a more functional approach?

use Data::Dump::Streamer; my @ListOfRecords = qw(1 a 2 b 3 c 4 d); my %MappingOfRecords = reverse @ListOfRecords; Dump \%MappingOfRecords;

Prints:

$HASH1 = { a => 1, b => 2, c => 3, d => 4 };

True laziness is hard work

Replies are listed 'Best First'.
Re^2: Transforming a for loop to a more functional approach?
by PoorLuzer (Beadle) on Mar 03, 2009 at 02:27 UTC
    But ofcourse! The first element is the key and the next is its value! What's wrong with me :-(
    Nice answer both of you!

    An unrelated question, why not just :
    use Data::Dumper;

      Habit mostly. I like Streamer's default output better and I don't have to remember to print the result:

      use Data::Dumper; use Data::Dump::Streamer; my @ListOfRecords = qw(1 a 2 b 3 c 4 d); my %MappingOfRecords = reverse @ListOfRecords; print Dumper \%MappingOfRecords; Dump \%MappingOfRecords;

      Prints:

      $VAR1 = { 'c' => '3', 'a' => '1', 'b' => '2', 'd' => '4' }; $HASH1 = { a => 1, b => 2, c => 3, d => 4 };

      True laziness is hard work