"Brett W. McCoy" wrote:
>
> Then you can use 'for(my $i = 0; $i < @array; $i++)'. In your example
> above, you are incrementing $i twice (first postincrement, then
> preincrement). It doesn't make sense (to me, at least) to have an index
> counter, and then still assign the array element to a t
Thanks for all the help :)
"Brett W. McCoy" wrote:
>
> On Tue, 18 Sep 2001, Andrea Holstein wrote:
>
> > > On Tue, 18 Sep 2001, Andrea Holstein wrote:
> > >
> > > > Try
> > > > for (my $i=0, my $var = $array[$i]; $i < @array; $i++, $var =
> > > > $array[++$i]) {
> > > >...
> > > > }
> > >
On Tue, 18 Sep 2001, Andrea Holstein wrote:
> > On Tue, 18 Sep 2001, Andrea Holstein wrote:
> >
> > > Try
> > > for (my $i=0, my $var = $array[$i]; $i < @array; $i++, $var =
> > > $array[++$i]) {
> > >...
> > > }
> >
> > Good Heavens! Why would you go to all of that trouble when a simple
> >
"Brett W. McCoy" schrieb:
>
> On Tue, 18 Sep 2001, Andrea Holstein wrote:
>
> > Try
> > for (my $i=0, my $var = $array[$i]; $i < @array; $i++, $var =
> > $array[++$i]) {
> >...
> > }
>
> Good Heavens! Why would you go to all of that trouble when a simple
> foreach will do?
>
You're right,
: Re: Index of foreach
Rasoul Hajikhani wrote:
>
> Hi there,
> is there any way to know what is the "current" index value in a foreach
> loop?
>
> EX:
>
> foreach my $var (@array)
> {
> # need the index of the array
> }
>
> Thanks in advance.
On Tue, 18 Sep 2001, Andrea Holstein wrote:
> Try
> for (my $i=0, my $var = $array[$i]; $i < @array; $i++, $var =
> $array[++$i]) {
>...
> }
Good Heavens! Why would you go to all of that trouble when a simple
foreach will do?
-- Brett
http://www.ch
Rasoul Hajikhani wrote:
>
> Hi there,
> is there any way to know what is the "current" index value in a foreach
> loop?
>
> EX:
>
> foreach my $var (@array)
> {
> # need the index of the array
> }
>
> Thanks in advance.
> -r
Try
for (my $i=0, my $var = $array[$i]; $i < @array; $i++, $
On Mon, 17 Sep 2001, Rasoul Hajikhani wrote:
> Hi there,
> is there any way to know what is the "current" index value in a foreach
> loop?
>
> EX:
>
> foreach my $var (@array)
> {
> # need the index of the array
> }
Just index through the array this way:
foreach my $var (0..$#array) {
you can run a counter inside the loop
Pierre
>From: Rasoul Hajikhani <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Index of foreach
>Date: Mon, 17 Sep 2001 12:23:51 -0700
>
>Hi there,
>is there any way to know what is the "current" index value in
Hi there,
is there any way to know what is the "current" index value in a foreach
loop?
EX:
foreach my $var (@array)
{
# need the index of the array
}
Thanks in advance.
-r
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
10 matches
Mail list logo