什么是Perl字符串文字?
字符串是字符序列。它们通常是用单引号(')或双引号(“)引起来的字母数字值。它们的工作方式与UNIXshell引号非常相似,在此您可以使用单引号和双引号。
双引号字符串文字允许变量插值,而单引号字符串则不允许。当某些字符以反斜杠开头时,它们具有特殊含义,它们用于表示换行符(\n)或制表符(\t)。
您可以将换行符或以下任何转义序列直接嵌入在双引号字符串中-
示例
让我们再次看看字符串在单引号和双引号之间的行为。在这里,我们将使用上表中提到的字符串转义符,并将使用标量变量来分配字符串值。
#!/usr/bin/perl # This is case of interpolation. $str = "Welcome to \nnhooo.com!"; print "$str\n"; # This is case of non-interpolation. $str = 'Welcome to \nnhooo.com!'; print "$str\n"; # Only W will become upper case. $str = "\uwelcome to nhooo.com!"; print "$str\n"; # Whole line will become capital. $str = "\UWelcome to nhooo.com!"; print "$str\n"; # A portion of line will become capital. $str = "Welcome to \Unhooo\E.com!"; print "$str\n"; # Backsalash non alpha-numeric including spaces. $str = "\QWelcome to nhooo's family"; print "$str\n";
输出结果
这将产生以下结果-
Welcome to nhooo.com! Welcome to \nnhooo.com! Welcome to nhooo.com! WELCOME TO nhooo.COM! Welcome to nhooo.com! Welcome\ to\ nhooo\'s\ family
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬