我需要这个脚本来分割大写字母和数字。我已经将大写字母部分分开工作,但我似乎无法弄清楚它的数字方面。
需要的结果:Hvac System 8000 Series :: Heating System 8000 Series :: Boilers
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
my $Last_URL = "HvacSystem8000Series/HeatingSystem8000Series/Boilers";
my ($Cat,$Sub1,$Sub2) = split(/\//, $Last_URL, 3);
if ($Sub2) {
$Last_URL = "<b>$Cat :: $Sub1 :: $Sub2</b>";
}
else {
$Last_URL = "<b>$Cat :: $Sub1</b>";
}
my @Last_URL = $Last_URL =~ s/(.)([A-Z][^A-Z][^0-9])/$1 $2/g;
print "$Last_URL";
答案 0 :(得分:1)
一些s///
转换将为您提供所需的信息:
for ($Last_URL) {
s/ ([a-z]) ([A-Z0-9]) / "$1 $2" /egx; # Foo123 -> Foo 123
s/ ([0-9]) ([A-Z]) / "$1 $2" /egx; # 123Bar -> 123 Bar
s! / ! " :: " !egx; # / -> " :: "
}
print $Last_URL, "\n";
答案 1 :(得分:0)
我建议你只使用正则表达式匹配来查找字符串中所有必需的“单词”,然后用空格连接它们。该计划表明。它将/
计为一个单词,因此这些只能替换双冒号来完成该过程
use strict;
use warnings;
my $Last_URL = "HvacSystem8000Series/HeatingSystem8000Series/Boilers";
(my $string = join ' ', $Last_URL =~ m<[A-Z][a-z]*|\d+|/>g) =~ s|/|::|g;
print $string;
<强>输出强>
Hvac System 8000 Series :: Heating System 8000 Series :: Boilers
答案 2 :(得分:0)
像pilcrow的答案,但是,你知道,不同
#!/usr/bin/env perl
use strict;
use warnings;
my $string = "HvacSystem8000Series/HeatingSystem8000Series/Boilers";
$string =~ s/(?<=\p{Ll})(?=\p{Lu}|\pN)/ /g;
$string =~ s/(?<=\pN)(?=\p{Lu})/ /g;
$string =~ s'/' :: 'g;
print "$string\n";