在Perl中打印字符串 [英] Printing string in Perl

查看:210
本文介绍了在Perl中打印字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我想要做的:

有没有一个简单的方法,使用子例程可能在Perl中打印一个字符串,而不会转义每个特殊字符? / p>

 打印DELIMITER<我不在乎这里是什么> DELIMITER 

显然,如果我可以把一个字符串作为分隔符而不是特殊字符/ p>

解决方案

perldoc perlop ,Quote and Quote-like Operators下面包含你需要的一切。


我们通常将引号视为文字值,在Perl中,它们作为运算符,提供各种插值和模式匹配
功能。 Perl为这些行为提供了习惯性的引用字符,但也为您提供了一种方式来为任何
选择您的报价字符。在下表中,{}表示您选择的任何一对分隔符。

 习惯通用含义Interpolates 
''q {} Literal no
qq {}文字是
``qx {}命令是*
qw {}单词列表no
// m {}模式匹配是*
qr {}模式是*
s {} {}替换是*
tr {} {}音译否(但见下文)
< EOF here -doc yes *

*除非分隔符为''。



Is there an easy way, using a subroutine maybe, to print a string in Perl without escaping every special character?

This is what I want to do:

print   DELIMITER <I don't care what is here> DELIMITER

So obviously it will great if I can put a string as a delimiter instead of special characters.

解决方案

perldoc perlop, under "Quote and Quote-like Operators", contains everything you need.

While we usually think of quotes as literal values, in Perl they function as operators, providing various kinds of interpolating and pattern matching capabilities. Perl provides customary quote characters for these behaviors, but also provides a way for you to choose your quote character for any of them. In the following table, a "{}" represents any pair of delimiters you choose.

Customary  Generic        Meaning        Interpolates
    ''       q{}          Literal             no
    ""      qq{}          Literal             yes
    ``      qx{}          Command             yes*
            qw{}         Word list            no
    //       m{}       Pattern match          yes*
            qr{}          Pattern             yes*
             s{}{}      Substitution          yes*
            tr{}{}    Transliteration         no (but see below)
    <<EOF                 here-doc            yes*

    * unless the delimiter is ''.

这篇关于在Perl中打印字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆