Date: Tue, 04 Sep 2001 18:30:46 +0100 From: Jasper McCrea Subject: Re: Why doesn't this regex work? Message-Id: <3B950FC6.16D6523F@guideguide.com> Benoit Gauthier wrote: > > (2001.09.04, 13:18) > > In my view, this code should truncate the variable to 20 characters. > It does not work. Why? > > $data = "1234567 101234567 201234567 30"; > print "$data\n"; > > $data =~ s/(.{0-20})/$1/; > print "$data\n"; for both of these, replace {0-20} with {0,20}. This s/// won't do anything, because it's replacing the first 20 characters with the same 20 characters, and not affecting the rest (after you change the - to a ,). > > $data =~ /(.{0-20})/; > $data = $1; > print "$data\n"; This does work when you change the regex. Although for just grabbing the first 20 characters, I'd be tempted to use: substr($string, 0, 20) 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"