Re: perl "alternating foreach" feature idea



"Erik 2.0" <erik@xxxxxxx> writes:

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";
}

an odd number of values in @pairs would cause an extra iteration with
$val set to undef

Great idea! When you've implemented it, you should send your patch to p5p
to get it integrated with mainline Perl.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
.



Relevant Pages

  • Re: perl "alternating foreach" feature idea
    ... support an array of variables as the iterator as well as just a ... scalar. ... this would cause perl to alternate across the array: ...
    (comp.lang.perl.misc)
  • Re: opinions on standard iterations?
    ... have a look at Eric Roode's just-released Iterator module now ... >> Order Perl book. ... solve the semipredicate problem. ... It's somewhat counter-intuitiv do have an array that only supports SHIFT ...
    (comp.lang.perl.misc)
  • Re: sharing a variable across two scripts.
    ... variable or array or a hash) which can be shared across two different batch ... Yes - Perl calls it a "module". ... Web Hosting by West Virginians, ...
    (comp.lang.perl.misc)
  • Re: A question about lists
    ... No conversion is needed - an array is a variable that contains a list. ... Web Hosting by West Virginians, ... Cocoa programming in Perl: http://camelbones.sourceforge.net ...
    (comp.lang.perl.misc)
  • Re: Learning Perl
    ... it should be an array, ... Then they'd be completely inaccessible to beginners. ... that should be my $var. ... so why is it redundant to point out that Perl is different from C here? ...
    (comp.lang.perl.misc)