in reply to Escaping special characters for POD output

s/</E<lt>/g will do unless you want to build tags dynamically too. (Then you also have to escape ">", and possibly "|" and "/" too.)


Note that you probably want one of the following here:

Compare using Perl's C<E<lt>=E<gt>> instead of C<cmp>
or
Compare using Perl's C<< <=> >> instead of C<< cmp >>

Replies are listed 'Best First'.
Re^2: Escaping special characters for POD output
by perlancar (Hermit) on Dec 15, 2019 at 12:44 UTC

    These need to be escaped too:

    • = at the start of the string (or line), to avoid interpretation of command.
    • Space or tab at the start of the string (or line), to avoid verbatim interpretation.

    Was hoping for an existing routine to use, but will package this routine into a new CPAN module if there is none.

        Should have known I was missing things.


        The module doesn't escape «>» which is significant when generating the content of tags.

        my $s = '$a <=> $b'; my $pod = "C<" . pod_quote($s) . ">"; # Fails

        The modules doesn't escape «/» and «"» which are significant when generating the content of L<> tags.

        my $s = 'Module for This/That'; my $pod = "L<" . pod_quote($s) . "|Some::Module>"; # Fails

        Creating a hash with the replacements should be faster than what you're using now.

        Note that «<» only requires escaping when preceded by an ASCII capital letter.