No, not really. That only works if $1 happens to
be undefined. Which you can't count on. Watch:
#!/usr/bin/perl
use strict;
use warnings;
"meep" =~ /(.*)/; # Set $1.
my $address1 = "Tsjakka"; # Will match.
my $address2 = "Tsjakka!"; # Will not match.
{
$address1 =~ /^([A-Za-z0-9öäåÖÄÅ][A-Za-zöäåÖÄÅ0-9\s\-\.\,]*)$/;
$address1 = $1;
}
{
$address2 =~ /^([A-Za-z0-9öäåÖÄÅ][A-Za-zöäåÖÄÅ0-9\s\-\.\,]*)$/;
$address2 = $1;
}
print $address1, "\n";
print $address2, "\n";
__END__
Tsjakka
meep
$address2 doesn't become undef. The solution is much simpler. The regex will either match the entire string,
or there's no match. So, we could just do:
/^([A-Za-z0-9öäåÖÄÅ][A-Za-zöäåÖÄÅ0-9\s\-\.\,]*)$/
or $_ = undef for $address1, $address2;
Abigail |