Reputation: 107
A previous post looks close to what I would like to try: Multiple Substitutions
Here are the substitutions I am trying to make:
$description =~ s/\"/\\"/g;
$description =~ s/\n/<br>/g;
When I view my CGI
script using UltraEdit
it looks to be incorrect. If I comment out the first line ($description =~ s/\"/\\"/g;)
all code looks good.
I don't see what the error is?
Upvotes: 1
Views: 238
Reputation: 49097
With active file being a Perl syntax highlighted file as indicated in status bar at bottom of main window of UltraEdit by string Perl, open in UltraEdit from main menu Advanced - Configuration - Editor Display - Syntax Highlighting.
Perl is already selected in list of Installed wordfiles (or Language in older versions of UltraEdit). Clicking on button Open opens the wordfile containing the syntax highlighting definitions for Perl. The configuration dialog should be closed with Cancel.
The syntax highlighting wordfile for Perl installed with UltraEdit v22.0 has as first line:
/L5"Perl" PERL_LANG EnableMLS Line Comment = # Line Comment Preceding Chars = [~[^]^^$/\(] Block Comment On = =pod Block Comment Off = =cut Block Comment On Alt = =item Block Comment Off Alt = =cut Escape Char = \ File Extensions = CGI PL PM PLX
Important on this syntax highlighting issue are:
EnableMLS
which enables multi-line string highlighting as in Perl a string can span over multiple lines.
Escape Char = \
which defines the escape character for double and single quotes inside strings.
String Chars = "'
not present here resulting in using the internal defaults for characters marking start and end of a string which is a double quote and a single quote.
UltraEdit has no real Perl language intellisense for syntax highlighting. So it does not know that the double quotes on first line of your example block are inside a Perl regular expression and should be therefore completely ignored for string highlighting.
The first double quote in the regular expression is ignored as being escaped with a backslash. But the second double quote is not escaped and therefore syntax highlighting engine of UltraEdit interprets it as start of a string and highlights now everything up to next not escaped double quote as a string.
The second double quote could be also escaped with a backlash to get the syntax highlighting here correct in UltraEdit, i.e.
$description =~ s/\"/\\\"/g;
Whether the first nor the second double quote must be for Perl interpreter escaped in this regular expression. But doing it nevertheless helps to get this line correct highlighted in UltraEdit and most likely most other text editors.
The wordfile for Perl can be closed as nothing can be done in the wordfile regarding this syntax highlighting issue.
I agree with comment written by Lucas Trzesniewski: Only perl can parse Perl.
By the way: By adding just a single quote or just a double quote to a color group on a separate line, it would be possible to highlight single quote strings with a different color than double quoted strings. For example appending
/C9"Single Quoted Strings"
'
results in highlighting single quoted strings with color and font style defined for color group 9 when using UltraEdit >= v17.00 supporting up to 20 color groups whereas double quoted strings are still highlighted with color and font style defined for strings. UltraEdit < v17.00 as well as UEStudio < v11.00 support only up to 8 color groups. More about syntax highlighting definitions can be read on UltraEdit forum page template for syntax highlighting language wordfile.
Upvotes: 2
Reputation: 6602
I do not have UltraEdit, but I sometimes encounter the same situation with Emacs perl-mode. The solution is usually to add a comment with a closing quote character, i.e.:
$description =~ s/\"/\\"/g; # " Satisfy the angry syntax highlighting gremlins
$description =~ s/\n/<br>/g;
Your mileage may vary.
Upvotes: 1