Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

concat '\' with word

by Anonymous Monk
on May 27, 2003 at 12:05 UTC ( #260971=perlquestion: print w/replies, xml ) Need Help??

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?

    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.


      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;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://260971]
Approved by Tanalis
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2023-05-30 04:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found