I have the following code, used to manipulate the postcode entered depending on the format. U = uppercase, L = Lowercase, NS = No space, and SP = a space in correct place.
Code: Select all
#!/usr/bin/perl
use strict;
use CGI ':standard';
my ($postcode, $format);
print "Content-type: text/html\n\n";
$postcode = param('postcode');
$format = param('format');
if ($postcode =~ /\D{2}\d{1,2}\s*\d\D{2}/)
{
if ($format =~ /U/)
{
$postcode = uc($postcode);
print "$postcode\n";
}
elsif ($format =~ /L/)
{
$postcode = lc($postcode);
print "$postcode\n";
}
elsif (($format =~ /ns/) or ($format =~ /NS/))
{
$postcode =~ s/\s//g;
print "$postcode\n";
}
elsif (($format =~ /sp/) or ($format =~ /SP/))
{
$postcode =~ s/\s//g; #clear out spaces
my $postcodergt = substr($postcode,-3);
my $postcodelft = substr($postcode,0,-3);
$postcode = $postcodelft." ".$postcodergt;
print "$postcode\n";
}
else
{
print "Invalid Data";
}
}
else
{
print "invalid data\n";
}The problem is, when no format is entered i need the $postcode entered to be outputed as it is. Also if the NS or SP formats are not used, and a space is in a different position i.e (GH16S Y). I need the space to be in the proper position i.e (GH1 6SY).
Any help would be great, Thanks
Sami P