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: Regular Expressions:
I found bug in perl, do you know the workaround?

 



sysprogerz
New User

Sep 21, 2009, 4:07 AM

Post #1 of 2 (2403 views)
I found bug in perl, do you know the workaround? Can't Post

Hello,

I am making this batch file :

as.sh
find="aaa";
perl -pi -e 's/$find/zzz/g' as.txt

and this file:

as.txt
aaabbbccc

When i run the as.sh, it gives :
zzzaaabbbccc

It is supposed to replace aaa with zzz, anyone knows why?

thx


shawnhcorey
Enthusiast


Sep 21, 2009, 6:28 AM

Post #2 of 2 (2401 views)
Re: [sysprogerz] I found bug in perl, do you know the workaround? [In reply to] Can't Post


In Reply To
Hello,

I am making this batch file :

as.sh
find="aaa";
perl -pi -e 's/$find/zzz/g' as.txt

and this file:

as.txt
aaabbbccc

When i run the as.sh, it gives :
zzzaaabbbccc

It is supposed to replace aaa with zzz, anyone knows why?

thx


Yes.

Oh, you want to know why too?

perl -pi -e "s/$find/zzz/g" as.txt

Using single quotes means $find is not expanded so perl sees: perl -pi -e 's//zzz/g' which means subsitute at the first opportunity, which is the beginning of the line.

__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