Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing string in Perl

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.

like image 491
Jean Avatar asked Dec 31 '25 09:12

Jean


1 Answers

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 ''.
like image 192
Ether Avatar answered Jan 02 '26 00:01

Ether



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!