Perl:Perl的一些应用例子。
1. 如何把一个字符串中的所有大写字符转成小写?my $name="I am John";
$name=~s/*/\L$&/g;
print $name;
转成小写:
$name=~s/*/\U$&/g;
2. 给函数传多个哈希值。
sub printh(%%)
{
print @_;
}
my %h1 = ('a',1,'b',2,'c',3);
my %h2 = ('d',4,'e',5,'f',6);
printh(%h1, %h2);
3. for循环的一个特殊例子:
for ($_="good";s/(.)//;) {
print "One character is: $1\n";
}
页:
[1]