Re: $escalar = @array? and regexs
- From: John Bokma <john@xxxxxxxxxxxxxxx>
- Date: 8 Dec 2006 04:36:43 GMT
Mirco Wahab <wahab@xxxxxxxxxxxxxxxxxxx> wrote:
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;
As Ruud noted, you need only to check 0 .. ( @Var/2 ) - 1, or 0 .. $#Var -
1 (assuming your array is zero based indexed).
BTW using $var and $Var would confuse the bleep out of me :-D.
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
.
- References:
- $escalar = @array? and regexs
- From: Winston
- Re: $escalar = @array? and regexs
- From: Mirco Wahab
- Re: $escalar = @array? and regexs
- From: John Bokma
- Re: $escalar = @array? and regexs
- From: Dr.Ruud
- Re: $escalar = @array? and regexs
- From: Mirco Wahab
- $escalar = @array? and regexs
- Prev by Date: Re: Perl storing huge data(300MB) in a scalar
- Next by Date: Re: ActiveState Perl for Win XP
- Previous by thread: Re: $escalar = @array? and regexs
- Next by thread: Re: $escalar = @array? and regexs
- Index(es):
Relevant Pages
|