首页 > 试题广场 >

用熟悉的脚本语言完成以下功能。

[问答题]
用熟悉的脚本语言完成以下功能。
a、一段html语言,找到第一个“hello the world”,删除“the” 。
b、把html里面所有的“hello the world”都替换成“hello world”。
#!/usr/bin/perl -w
use strict;
open FILEHANDLD,"html.txt" or die "this
file can not open $!\n";
my @fileMSG = <FILEHANDLD>;
 
# Replace all "hello the world" to
"hello world"
sub TstReplaceAll
{
    my $msg = join "",@fileMSG;
    $msg = ~s/hello the world/hello world/g;
    print $msg;
}
 
 
# Replace Once "hello the world" to
"hello world"
sub TstReplaceOnce
{
    my $msg = join "",@fileMSG;
    $msg = ~s/hello the world/hello world/;
    print $msg;
}
TstReplaceAll();
TstReplaceOnce();

发表于 2014-11-14 15:11:25 回复(0)