Perl : Troubles to replace a string.
Hello,
I'm a newbie in Perl and I created a file with a DB dump (by using mysqldump). I would like to open this dump file "dump.txt" and change it to add some parameters with a perl script. Here is my code: $file='dump.sql'; #open the file open(FILE, $file); @lines = <FILE>; close(FILE); @lines=~ s/VALUES (/VALUES (1234,5678/; print @lines; But I receive the following error : "Can't modify array dereference i n substitution..." I assume that this happen because I'm using an array but the question is "How can I do that in another way?". Also, I would like to know which one is the fastest to do this kind of modification in a file with more than 2000 lines "bash or perl"? Thank in advance. Alain. |
Maybe:
Code:
foreach $line (@lines) |
Thank you,
I tried it but I still get an error. I tried 6 syntaxes: foreach $line (@lines) { $line=~ s/VALUES (/VALUES (1234,5678/ } ----------------------------------- foreach $line (@lines) { $line=~ s/'VALUES ('/'VALUES (1234,5678/' } -------------------------------------- foreach $line (@lines) { $line=~ s/"VALUES ("/"VALUES (1234,5678/" } and same syntax also ending by ; Thanks in advance. Regards. Alain. |
Sorry, my mistake:
you have to protect ( ) chars, because these are reserved for special meaning in pattern so: Code:
foreach $line (@lines) there is no need to have " or ' in regular pattern, its another pattern that will be searched. ; after the last commnd in the block is only optional. |
Thanks a lot it works fine.
Alain. |
All times are GMT -5. The time now is 03:26 AM. |