in reply to Re: searching for strings
in thread searching for strings

Consider these two data elements: CBG99 and CBG100. When they are placed into your code, the match is CBG99;CBH00 Very fun problem here! :-) -P

Replies are listed 'Best First'.
Re^3: searching for strings
by Zielony (Acolyte) on Aug 06, 2007 at 16:00 UTC
    #!/usr/bin/perl use strict; sub simstr { $_ = shift; /([a-z]|\d+)$/i; my $ch = $1; $ch++; $ch =~ s/.*(.)$/$1/ if ($ch =~ /[a-z]/i); substr ($_, -(length $1)) = $ch; $_; } for (<DATA>) { chomp; print "$_;" . simstr ($_) . "\n"; } __DATA__ AAA30 BBC5 SHT12H DAL33B BBC49 AAA31 DAL33A BBC6 SHT12G BBC50 CBG99 WXYZ
    Now it works and isn't even a bit funny. ;-)