How to replace a "/" in perl

C

chunji08

I have a list of sql files, in which it ends with a "/". Now I want to
replace it with "//end" for all files. And here is my perl command,
"
perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
"

Suprisingly it does not work. Does someone know how to make it
working ?

I am using perl 5.6.1 on Linux.


Charlie
 
A

A. Sinan Unur

(e-mail address removed) wrote in @v45g2000cwv.googlegroups.com:
I have a list of sql files, in which it ends with a "/". Now I want to
replace it with "//end" for all files. And here is my perl command,
"
perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL
"

Suprisingly it does not work.

It does not work is a bad description. Please read the posting
guidelines for this group.

#!/usr/bin/perl

use strict;
use warnings;

while ( <DATA> ) {
s{^/$}{//end} and print;
}

__DATA__
/
/
/
/
/
/
/

Sinan
 
C

comp.llang.perl.moderated

I have a list of sql files, in which it ends with a "/". Now I want to
replace it with "//end" for all files. And here is my perl command,
"
perl -pi.org -e 's/^\/$/^\/\/end$/' *.SQL


* if you add -w to the options, you'll
get a fatal syntax error,

perl -pi.org -we ...

* you don't want the ^ on the left-hand side

for regular expression help, see:

perldoc perlrequick
perldoc perlretut

* use alternative substitution delimiter to
avoid backslash-itis, eg.,

s{something}{for something else}
 
C

chunji08

(e-mail address removed) wrote in @v45g2000cwv.googlegroups.com:



It does not work is a bad description. Please read the posting
guidelines for this group.

#!/usr/bin/perl

use strict;
use warnings;

while ( <DATA> ) {
s{^/$}{//end} and print;

}

__DATA__
/
/
/
/
/
/
/

Sinan

My Fault.
The correct answer should be:
"
perl -pi.org -e 's/^\/$/\/\/end/' *.SQL
"

C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top