develooper Front page | perl.beginners | Postings from January 2002

Simple regex string replacement problem

Thread Next
January 10, 2002 08:03
Simple regex string replacement problem
Message ID:
Hello All,

I know this is very basic and similar items have come up numerous times
on this list, but I'm not sure where my boneheaded mistake is here.

I have a file which has many strings like "$something[0]" through "something[20]"
amongst other text (quotes only provided here for clarity).

What I want to do is replace these strings with: "$SOMETHING0" through "$SOMETHING20".

When I run:

perl -p -i -e 's/something\[([0-9][0-9]?)\]/SOMETHING$1/g' file

"file" becomes 0 bytes.  I'm not quite sure why this is happening; is it
a fault of my regex?  Or - maybe less likely - could it because "file" is
on a file system Samba mounted from Linux to NT?  I know there is a command
line option to use a backup file instead of modifying the original, but
no matter how many times I've seen this, I can't recall it.

Thanks much,


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About