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

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

问题描述

有一个简单的方法,使用子例程也许,在Perl中打印一个字符串而不转义每个特殊字符?

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

这是我想要做的: / p>

This is what I want to do:

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

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

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

推荐答案

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

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


作为文字值,在Perl中它们作为运算符,提供各种内插和模式匹配
能力。 Perl为这些行为提供了习惯引用字符,但也为您提供了一种方式来选择
中的任何一个的引号字符。在下表中,{}代表您选择的任何分隔符。

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天全站免登陆