Erwin Zavala wrote: > My export.txt file has data in the format > > Joe Doe mail: [EMAIL PROTECTED] > > I want my script to replace mail for email. At the end of the script > I get an empty file? Why what am i doing wrong > > #!/user/bin/perl > > open(openFile, "<export.txt"); > open(writeFile, ">export.txt"); > while(<openFile>) > { > print writeFile if s/mail/email/ ; > }
You can use the -i qualifier to Perl to do an in-place edit: perl -pi -e 's/mail/email/' export.txt or, within a script: #perl use strict; @ARGV = 'export.txt'; $^I = ''; while (<>) { s/mail/email/; print; } __END__ beware, though, that there will be no backup of your file if the modifications are not what you wanted. To make a backup, write perl -pi '.bak' -e 's/mail/email/' export.txt or in the script, change the relevant line to $^I = '.bak'; and Perl will save you a backup file called export.txt.bak. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]