From: Jan Eden <[EMAIL PROTECTED]>
> I recently wrote a Perl script to convert 8-bit characters to LaTeX
> commands. The first version (which works just fine) looks like this
> (the ... indicates more lines to follow):
>
> >#!/usr/bin/perl -pw
> >
> >s/âÇ?/{\\glqq}/g;
> >s/âÇ?/{\\grqq}/g;
> >s/Ăí/\\'{a}/g;
> >s/Ăá/\\`{a}/g;
> >s/Ăó/\\^{a}/g;
> >s/ä/\\"{a}/g;
> >....
>
> Now I tried to use a hash instead of consecutive replacement commands.
> The second version looked like this:
>
> >#!/usr/bin/perl -w
> >
> >%enctabelle = ("âÇ?"=>"{\\glqq}",
> >"âÇ?"=>"{\\grqq}",
> >"Ăí"=>"\\'{a}",
> >"Ăá"=>"\\`{a}",
> >"Ăó"=>"\\^{a}",
> >....
> >
> >while (<>) {
> >    $zeile = $_;
> >    foreach $char (keys %enctabelle) {
> >        $zeile =~ s/$char/$enctabelle{$char}/g;
> >    }
> >    print $zeile;
> >}

You want something like this:

        my $re = join '|', keys %enctabelle;
        while (<>) {
            s/$re/$enctabelle{$1}/go;
            print $_;
        }
or

        my $re = join '|', keys %enctabelle;
        $re = qr/($re)/;
        while (<>) {
            s/$re/$enctabelle{$1}/g;
            print $_;
        }

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to