Re: $escalar = @array? and regexs



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."

.



Relevant Pages

  • Re: $escalar = @array? and regexs
    ... Mirco Wahab wrote: ... (I think the int() ... is implicit, but it doesn't harm much.) ...
    (comp.lang.perl.misc)
  • Re: $escalar = @array? and regexs
    ... (I think the int() ... is implicit, but it doesn't harm much.) ... grep returns a list, and that list can be huge. ...
    (comp.lang.perl.misc)
  • Re: $escalar = @array? and regexs
    ... (I think the int() ... is implicit, but it doesn't harm much.) ... and put it into my snippets dir: ...
    (comp.lang.perl.misc)
  • Re: why cant functions return arrays
    ... int f; ... for such a language restricton. ... have been able to pass and return fixed-size arrays by value by ... Since there were no prototypes in K&R, there was no way to inform the ...
    (comp.lang.c)
  • Re: Implementing an 8 bit fixed point register
    ... It seems like implementing ALU operations on such arrays would ... If one only wants int arithmetic and all-bits logic, ... def bitset ... your approach could be easily modified to support slices: ...
    (comp.lang.python)