Hi Gary,
> Unfortunately some strings have a 'S' instead of a 5 or a 'B' instead of a 8
>
> The fields are of the format
>
> Registration XX99XXX
> Stock no XX99999
> VIN XXXXXX99999
>
> I've been experimenting with translate to convert the letters to the correct
> digit, but can't work out an easy way to only translate the digits. There
> may genuinely be 'B' and 'S' in the 'X' positions.
You can use s///e to only tr the '9' entries:
(for the e-Modifier see e.g. [1, Regex Modifiers])
#!/usr/bin/env perl
use warnings;
use strict;
my $string = "Registration AASBBBB";
print "before: $string\n";
$string =~ s{^Registration\s*([a-zA-Z]{2})([0-9SB]{2})([a-zA-Z]{3})$}{
"Registration $1" . $2 =~ tr/SB/58/r . "$3"}e;
print "after: $string\n";
output:
before: Registration AASBBBB
after: Registration AA58BBB
is this what you want?
Regards, Simon
[1] http://onyxneon.com/books/modern_perl/
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/