How to Delete Double Quotes in a String in Perl
A string, in the Perl programming language, can contain any alphanumeric or special characters. If passing the string to another program, such as a database, you may need to remove special characters, including any double quotes. Removing double quotes also ensures that any user created strings are in the correct form. The Perl "tr" -- or transliteration -- function is used to strip the double quotes from a string. The "tr" function can be used to strip any other character from a string, also.
Instructions
-
-
1
Open a blank plain text document.
-
2
Type the following line to start the Perl script:
#!/bin/perl
-
-
3
Type the following line to create a string variable that contains double quotes:
$mystring ="\"My name is George.\"";
-
4
Type the following line to print the original string:
print $mystring ."\n";
-
5
Type the following line to remove the double quotes from the string:
$mystring =~ tr/"//d;
-
6
Type the following line to print the string with the double quotes removed:
print $mystring."\n";
-
7
Save the file with the ".pl" file extension.
-
1