in reply to Remove $

If there is no way to stop the interpolation of the $/ in your input, then perhaps you could localize it just within that context. For instance:

{ local $/ = '/'; $text = "db1$/SQL/GEMINI/StoredProcs/pboValidateClientRefNo_ClientID +.sql"; print "$text\n"; }
Prints:

db1/SQL/GEMINI/StoredProcs/pboValidateClientRefNo_ClientID.sql
Make sure that this exception doesn't flow over into the rest of your code. You probably don't want a screwed-up new-line character wandering around your script.

Replies are listed 'Best First'.
Re^2: Remove $
by ikegami (Patriarch) on Aug 27, 2007 at 15:58 UTC
    But there is a way... backslashing the $:
    $text = "db1\$/SQL/GEMINI/StoredProcs/pboValidateClientRefNo_ClientID

    If he can change the code to add { local $/ = '/'; ... }, he can change the code to add $.

    I consider your advice very dangerous.

      I understand the danger. That's why I gave the warning at the end. However, notice the context of the string in which he's interested. It's a filepath, which means that it might not have been input by hand, but by some directory walker. In that case he may not be able to insert a '\' or catch the '$' before it interpolates. In that extreme case, he may choose to change the new-line character, but should only do so temporarily. Of course it's dangerous, but it's the bad-boy solutions that perl allows that make it such a wonderful language to use. Document it well, and be smart about it, and it should work fine.

        Not so! Interpolation only occurs in string literals, and string literals only exist in source code. Your directory walker would deal with strings, not string literals.

        Either he's dealing with a string literal where local $/ would be the wrong solution, or he's dealing with a string (where local $/ wouldn't help.