Re: $escalar = @array? and regexs



Thus spoke Dr.Ruud (on 2006-12-07 13:19):

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

OK, I checked the code, modified it slightly
and put it into my snippets dir:

my $var = 'Reliefpfeiler'; # something german
my @Var = split '', $var;
print "p'drome"
if not grep lc $Var[$_] ne lc $Var[@Var-1-$_], 0..@Var/2;


Regards & thanks

M.

.



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.) ... For small arrays (like less than 100 elements or so, ...
    (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: _JoyDef and _Control
    ... a declaration with no type defaults to int ... the problem wasn't "implicit int" but the LALRconflict created ... 'typedef' itself. ...
    (comp.lang.c)
  • Re: main return value stange question
    ... value (relying on implicit int), ... Now we know it won't compile, ... Dig the even newer still, yet more improved, sig! ...
    (comp.lang.c)