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

RE: what's with 'with'? (was: [aliasing - was:[nice2haveit]])

From:
Sterin, Ilya
Date:
July 19, 2001 12:58
Subject:
RE: what's with 'with'? (was: [aliasing - was:[nice2haveit]])
Message ID:
E989263E0496D3119C440008C79185340280C7AC@cibermail2.ciber.com
@foo = ("foo1", "foo2");
@bar = ("bar1", "bar2");

 for ( \@foo, \@bar ) { 
    print "$_->[0] : $_->[1]\n"; 
  } 

will output

foo1 : foo2
bar1 : bar2

I was thinking more of iterating through them at the same time, which would
sort of like compare them.  I believe this was the initial topic of this
thread (I believe, that was about two days ago, my mind might be going blank
though).

So my initial code (which I modified a little...)

for ( @foo, @bar ) {
  print "$_[0] : $_[1]\n";
}

for would set each element of the @_ array to correspond to the arguments in
for() , therfore $_[0] will equal to the current element of @foo and $_[1]
will equal to the corresponding element of @bar.  As I mentioned before this
can very easily be accomplished through 0..$#foo loop, but people disagreed
based on that it would be a nice option, in my opinion it's useless, but if
was implemented this could be a way:)

Ilya


-----Original Message-----
From: 'John Porter '
To: perl6-language@perl.org
Sent: 07/19/2001 1:46 PM
Subject: Re: what's with 'with'?  (was: [aliasing - was:[nice2haveit]])

Sterin, Ilya wrote:
> Well then maybe $_ can be a reference to a multidimensional array or
hash,
> and temp vars can be access like this.
> 
> for ( @foo, @bar ) {
>   print "$_->[0] : $_->[1]\n";
> }

That's bizarre and unnecessary.  We can already do this:

  for ( \@foo, \@bar ) {
    print "$_->[0] : $_->[1]\n";
  }

-- 
John Porter



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