| | |
String replacement in a file
![]() |
I have a very specific problem.
Does s/// work with strings that are contained in single quotes? I've been debugging and I'm trying to replace a string that contains a $ in it. If I use double quotes, it works for the string up until the $. If I use single quotes, it does not work with any string.
Here is my code; it involves file access, and file.data contains the string "testing $my string."
Does s/// work with strings that are contained in single quotes? I've been debugging and I'm trying to replace a string that contains a $ in it. If I use double quotes, it works for the string up until the $. If I use single quotes, it does not work with any string.
Here is my code; it involves file access, and file.data contains the string "testing $my string."
Perl Syntax (Toggle Plain Text)
#!/usr/bin/perl $s1 = "testing $my string"; $s2 = "testing $your string"; local ($^I, @ARGV) = ('.bak', 'file.data'); while (<>) { s/$s1/$s2/g; print; }
Perl Syntax (Toggle Plain Text)
#!/usr/bin/perl $s1 = "testing $my string"; $s2 = "testing \$your string"; local ($^I, @ARGV) = ('.bak', 'file.data'); while (<>) { s/\Q$s1\E/$s2/g; print; }
![]() |
Similar Threads
- Search string in a text file (C)
- Read a string from a binary file into a C or C++ string (C++)
- Read in a string from a text file (C)
- New User (C)
Other Threads in the Perl Forum
- Previous Thread: hi i have prob solve it plz
- Next Thread: Multiple scripts in one file
| Thread Tools | Search this Thread |





