in reply to searching for strings

#!/usr/bin/perl use strict; sub simstr { $_ = shift; if (/([a-z])$/i) { my $ch = $1; $ch++; $ch =~ s/.*(.)$/$1/; substr ($_, -1) = $ch; } elsif (/\d+$/) { $_++; } $_; } for (<DATA>) { chomp; print "$_;" . simstr ($_) . "\n"; } __DATA__ AAA30 BBC5 SHT12H DAL33B BBC49 AAA31 DAL33A BBC6 SHT12G BBC50

Replies are listed 'Best First'.
Re^2: searching for strings
by Philem (Acolyte) on Aug 06, 2007 at 14:43 UTC
    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
      #!/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. ;-)