Date: Fri, 05 Oct 2001 14:22:43 +0100 From: Jasper McCrea Subject: Re: Skipping following lines if the same Message-Id: <3BBDB423.CFC98433@guideguide.com> Laird wrote: > > Hi everyone, > > I've got this array > > aaa > aaa > bbbbb > cccc > cccc > c > ddd > ddd > fff > fff > fff > ffff > ffff > > and would like to transform it into this > > aaa > bbbbb > cccc > c > ddd > fff > ffff > > skipping following lines if the same. > But only following lines. > > I tried this but it doesn't work. > > #!/usr/bin/perl > open (IN,data); > @a=; > for (@a){ > $i++; > chomp $a[$i]; > print "$a[$i]\n" if /$a[$i]/ ne /$a[$i+1]/ > } > > Cordially > Ken you could use: my $last = ''; @a = map { $last eq $_ ? () : ($last = $_) } @a; unfortunately, if you have umpteen empty elements at the start, these will be included (not much of a problem if reading from a file). And it's only useful if you've slurped the whole file first. Jasper -- split//,'019617511192'. '17011111610114101114'. '21011141011840799901'. '17101174'; foreach(0.. # my $#_){$_[$_ # signature is too ++]^=$_[$_ # bignature --]^=$_[$_ ]^=$_[++ $_]if!($_% 2)}$g.=$_ ,chr($g)=~ /(\w)/&&($o.=$1and $g='')foreach@_; print"$o\n"