Re: perl "alternating foreach" feature idea



Erik 2.0 wrote:
dear perl people,

in the spirit of both perl's brevity and it's "do what i mean" array
contexts, it would be an appropriate feature for foreach loops to
support an array of variables as the iterator as well as just a
scalar. this would cause perl to alternate across the array:

for example:

foreach ($key, $val) in (@pairs) {
print "$key=$val\n";
}


This looks like a poor design of your data structure. If you sequence has
alternating elements of identifiers (aka keys) and values, then an AoA seems
to be a much more natural way to represent this data.
And iterating over an array that contains just the references to the data
pairs works beautifully with the existing Perl features as of today.

this syntax for an "alternating foreach" seems quite elegant to me.

Well, but your data structure is anything but.

jue


.



Relevant Pages

  • Re: array/vector indices
    ... >> Really, the feature you're looking for is at the level of application, ... >> not data structure. ... You want some coordinate translation to be applied ... A multidimensional array has a significantly different conceptual "look" ...
    (comp.lang.lisp)
  • Re: Latest version of glossary
    ... such as XML, refer to the use of the term within that "namespace" using ... An n-dimensional data structure, S, is one where each element of S ... Whenever mathematics is applied to anything, ... associative array (while trying to do something in JavaScript, ...
    (comp.databases.theory)
  • Re: combining hashes
    ... >>> A hash is an ordered data structure indexed by a specific key. ... My mind's eye sees it differently. ... c> An array is ...
    (comp.lang.perl.misc)
  • Re: how to read dynamic data structures from the kernel (was Re: reading routing table)
    ... could give us individual entries of the data structure on each call, ... steps for any given kernel subsystem -- we have data structures, ... bumping the references and adding pointers to the array. ... the global locks, and proceed lock, externalize, unlock, and copyout each ...
    (freebsd-net)
  • Re: Looking for advise on storring a complex array
    ... hashes etc. ... The trick is that I would not like to have to read back the entire array ... but you should look into using a database with a few ... This *really* depends on your data structure. ...
    (perl.beginners)