Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

can i get, \ + word = \word

Replies are listed 'Best First'.
Re: concat '\' with word
by arturo (Vicar) on May 27, 2003 at 12:17 UTC

    1. De rigeur snarky answer to the question you've asked: yes.
    2. Somewhat more helpful answer to the question you should have asked: perlintro, and while we're at it, How to RTFM.
    3. Hand-fed answer:
      # update Of course that should be '\' ... $foo = '/' . $bar;
    This is a *very* basic question, any worthwhile introduction to Perl should teach you about string concatenation. Thus, get thee to answer #2 before going *any* further with Perl.

    If not P, what? Q maybe?
    "Sidney Morgenbesser"

Re: concat '\' with word
by teabag (Pilgrim) on May 27, 2003 at 12:11 UTC
    uhr, sure,

    escape it with an extra "\",

    print "\\word"; prints: \word

    I think that's what you mean?

    Teabag
    Sure there's more than one way, but one just needs one anyway - Teabag

Re: concat '\' with word
by arthas (Hermit) on May 27, 2003 at 12:30 UTC
    You just need to use . (dot) instead of + (plus sign): while the latter is just for numbers, the first works with strings.
    $string = '\'.$string;
    You can find more information here.

    Michele.

      It's good that you pointed out the . (dot) operator, and I realize I'm being a tad pedantic, but...

      $string = '\'.$string;
      Will result in:
      Can't find string terminator "'" anywhere before EOF
      

      As teabag mentioned above, you need to escape the backslash thusly:

      $string = '\\'.$string;