Re: $escalar = @array? and regexs
- From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
- Date: Thu, 7 Dec 2006 13:19:38 +0100
John Bokma schreef:
Mirco Wahab:
[palindrome]
for (0 .. @Var-1) { ++$bad if lc $Var[$_] ne lc $Var[$#Var-$_] }
for ( 0 .. int( @var / 2 ) ) { .. }
for my $i ( 0 .. int( ($#var - 1) / 2 ) )
{
++$bad if lc $Var[$i] ne lc $Var[-1 - $i]
}
If there are 8 elements, then $# is 7, so elements 0..3 need to be
compared with 7..4.
If there are 9 elements, then $# is 8, so elements 0..3 need to be
compared with 8..5.
(I think the int() is implicit, but it doesn't harm much.)
For small arrays (like less than 100 elements or so, or more if the
programmers has counting problems), the "reverse" approach is more
attractive.
To show that a copy is made:
$ perl -wle '@a=(1,2,3); ${@a}[2]++; print @a'
124
$ perl -wle '@a=(1,2,3); ${reverse @a}[2]++; print @a'
123
--
Affijn, Ruud
"Gewoon is een tijger."
.
- Follow-Ups:
- Re: $escalar = @array? and regexs
- From: Mirco Wahab
- Re: $escalar = @array? and regexs
- From: John Bokma
- Re: $escalar = @array? and regexs
- References:
- $escalar = @array? and regexs
- From: Winston
- Re: $escalar = @array? and regexs
- From: Mirco Wahab
- Re: $escalar = @array? and regexs
- From: John Bokma
- $escalar = @array? and regexs
- Prev by Date: Re: two axis, two data sets GD::Graphic
- Next by Date: Re: HASH
- Previous by thread: Re: $escalar = @array? and regexs
- Next by thread: Re: $escalar = @array? and regexs
- Index(es):
Relevant Pages
|