in reply to character encoding ambiguities when performing regexps with html entities

What happens to $text afterwards?

As you can see if you view the produced HTML doc in your web browser, the bit you provided works fine.

my %allowed_text_code = ( '$\\alpha$' => 'α', '$\\beta$' => 'β', '$\\gamma$' => 'γ', '$\\delta$' => 'δ', '$\\theta$' => 'θ', '$\\pi$' => 'π', '\\degrees' => '°' ); my $text = join '', keys %allowed_text_code; foreach my $tex_key (keys %allowed_text_code) { $text =~ s/\Q$tex_key\E/$allowed_text_code{$tex_key}/g; } open(my $fh, '>', 'temp.html') or die; print $fh ("$text\n");

Replies are listed 'Best First'.
Re^2: character encoding ambiguities when performing regexps with html entities
by angelixd (Novice) on Sep 24, 2007 at 19:27 UTC

    So thankfully, it turns out that the problem i was trying to solve was still causing me grief. what happens to $text is that it gets dumped to another text file that describes the LaTeX sans comments, extraneous spacing, etc. That file is then searched for plaintext for web display, which is why i wanted to substitute the LaTeX tags for html entities. One of my coders was using straight unicode in the .tex files, and I felt that was a bad idea (mostly since we want to keep it simple), so that's why I'm doing this simple workaround.

    On a related note, is there a regular expression I can write that detects non-ascii characters? I really don't want to parse through a few ten thousands of LaTeX code...

      is there a regular expression I can write that detects non-ascii characters?

      Here are a couple easy ones:

      /[^\x00-\x7f]/ /[^[:ascii:]]/
      They both work whether or not the string happens to have its "utf8 flag" turned on.