develooper Front page | perl.perl6.language | Postings from July 2001

Re: array/hash manipulation [was :what's with 'with'?]

Thread Previous | Thread Next
From:
Jeremy Howard
Date:
July 20, 2001 17:40
Subject:
Re: array/hash manipulation [was :what's with 'with'?]
Message ID:
009601c1117d$ba00bfc0$0d00a8c0@optimaldecisions.com
"Sterin, Ilya" <Isterin@ciber.com> wrote:
> Hmmm. Didn't think about that.  That would be a nice way, that way you can
> manipulate it's behaviour depending with how many aliases you provide.
>
> for my $el1, $el2 ( (@foo, @bar) ) {
>     print "$el\n"
>  }
>
> $el1 and $el2 would of course be aliases, right?
>
I don't think that this special purpose notation is necessary. With the
improved 'want' proposed by Damian, the following should be easy to achieve:

  @a = (1,2,3,4);
  for ($b,$c) (@a) { print "$b $c"}
  # prints:
  # 1 2
  # 3 4
  %d = (a=>1, b=>2);
  for ($b,$c) (@a) { print "$b $c"}
  # prints:
  # a 1
  # b 2

Which with the merge() RFC makes the desired behaviour for multiple lists
easy:

  @a = (1,2);
  @b = (3,4);
  for ($b,$c) merge(@a,@b) { print "$b $c"}
  # prints:
  # 1 3
  # 2 4

So, no really new syntax, no special purpose behaviour, just the obvious
extension of for-iterators to list context, and the introduction of one new
function (which happens to have many other applications).



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About