On Jun 27, Peter Cline said:

>After studying examples in "Effective Perl Programming" I devised the 
>following working code snippet:
>
>@people{@newkeys} = @$contact{sort keys %$contact};

All a slice is, is a list of elements of the structure.

  @array[1,3,5]

is

  ($array[1], $array[3], $array[5])

And

  @hash{$x, $y, $z} = @other{$m, $n, $o};

is

  ($hash{$x}, $hash{$y}, $hash{$z}) =
    ($other{$m}, $other{$n}, $other{$o});

So doing something like:

  @people{@newkeys} = @$contact{sort keys %$contact};

is doing this:

  1. sort the keys of %$contact
  2. access the VALUES of %$contact in that order
  3. assign to the values of %people, whose keys are in @newkeys

A long-winded expression would be:

  @values = @$contact{sort keys %$contact};

  for (@newkeys) {
    $people{$_} = shift @values;
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **


Reply via email to