CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
substitution with hash elements

 



Jishnu
New User

Dec 6, 2010, 6:40 AM

Post #1 of 2 (606 views)
substitution with hash elements Can't Post

Hi,

I am working on a small script to automate my day to day work. The script was working fine until today when I started discovering problems. After debugging a bit, I have narrowed down the problem to a single line:


Code
$tmp1[1]=~s/$tmp/$jd_defines{$tmp}/;


Please let me know if there is something wrong with it? I intend to replace the first occurrence of $tmp in $tmp1[1] with $jd_defines{$tmp}. Is there a better/safer way to do it? Note: all variables are absolute paths and hence contain the character '/' multiple times.

Thanks in advance.


shawnhcorey
Enthusiast


Dec 6, 2010, 12:48 PM

Post #2 of 2 (592 views)
Re: [Jishnu] substitution with hash elements [In reply to] Can't Post

Try:

Code
$tmp1[1]=~s/\Q$tmp\E/$jd_defines{$tmp}/;



See `perldoc perlre` and search for /\\Q/ ans /\\E/
Also see `perldoc -f quotemeta`

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives