Hoi,
Naja, eigentlich schon, aber 'patschert' ist es trotzdem:
($straße,$hausnummer) = split(/\s*([0-9]+)/,$wohnort,2);
[...]
($straße, $hausnummer) = split /(?=[0-9])/, $wohnort, 2;
Hui, das ist interessant. Der Algorithmus ist sehr schnell:
#!/usr/bin/perl -w
use strict;
use Benchmark;
timethese(1000000,
{
regex => sub {
my $wohnort = 'Dorfstrasse17';
my ($str,$hnr) = $wohnort =~ m/^([^0-9]+)([0-9]+)$/;
},
splt1 => sub {
my $wohnort = 'Dorfstrasse17';
@kk = split(/[a-z]/i,$wohnort);
@kk = split(/[0-9]/,$wohnort);
},
splt2 => sub {
my $wohnort = 'Dorfstrasse17';
my ($str,$hnr) = split(/\s*([0-9]+)/,$wohnort,2);
},
splt3 => sub {
my $wohnort = 'Dorfstrasse17';
my ($str,$hnr) = split(/(?=[0-9])/, $wohnort, 2);
}
}
);
eof
H:\Perl\bin>perl bench.pl
Benchmark: timing 1000000 iterations of regex, splt1, splt2, splt3...
regex: 6 wallclock secs ( 5.16 usr + 0.00 sys = 5.16 CPU) @ 193836.01/s (n=1000000)
splt1: 15 wallclock secs (15.05 usr + 0.02 sys = 15.07 CPU) @ 66343.79/s (n=1000000)
splt2: 10 wallclock secs ( 9.06 usr + 0.00 sys = 9.06 CPU) @ 110326.57/s (n=1000000)
splt3: 6 wallclock secs ( 5.63 usr + 0.00 sys = 5.63 CPU) @ 177683.01/s (n=1000000)
H:\Perl\bin>