in reply to Hash newbie

Exactly. Your snippet is equivalent to:

my %h = (); foreach (0..$#FIELDS) { $h{$FIELDS[$_]} = $row[$_] } $result = \%h;

It's called a hash slice, and it should be documented in perldata.

Replies are listed 'Best First'.
Re: Hash newbie
by christiffer (Initiate) on Jan 28, 2005 at 15:52 UTC
    (FX: perldoc perldata). Aha! I have achieved a limited form of enlightenment. Thank you for endulging my laziness ;)

      ikegami explained that this uses a hash slice. He also showed an equivalent snippet that has the same effect as yours. But I'd like to show an equivalent snippet that might help you understand how the hash slice is doing its job:

      my %h = (); # @h{@FIELDS} = @row; ($h{$FIELDS[0]}, $h{$FIELDS[1]}, $h{$FIELDS[2]}, ...) = ( $row[0] , $row[1] , $row[2] , ...); $result = \%h;

      As you can see, a hash slice is simply a convenient syntax for doing something that is not altogether very complicated. Hopefully this helps you understand it.