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:
Strange behaviour

 



piagina
New User

Jul 10, 2007, 8:41 AM

Post #1 of 1 (148 views)
Strange behaviour Can't Post

I have recently started using perl to do regular expression search and replace operations eg.

perl -p -i -e 's/,/\n/g' some.file

to replace all the commas with newline characters in some.file, but I have noticed that often (but not always!) this results in some.file becoming empty. Using the -i switch to generate a back up seems to cure this

perl -p -i.bak -e 's/,/\n/g' some.file

strangely doing a cat of some.file before I run the perl command also seems to prevent the blanking of some.file.

I have a solution that works but I was wondering why the first version is unpredictable.

 
 


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

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