in reply to Combining two Reg Expressions with substitution

I'd go for:
$line =~ s/(gregarious)/\\underline{gregarious}/g && $line =~ s/\\underline\{(gregarious)\}/\\footnote{$1}/;

Abigail

Replies are listed 'Best First'.
Re: Re: Combining two Reg Expressions with substitution
by Nkuvu (Priest) on Nov 04, 2003 at 18:13 UTC
    But wouldn't that just work for a single line? The next line that contained gregarious would have its first occurrence footnoted. Which isn't what the OP was asking for. I think. Sometimes.

    No, wait, I see what it's doing now. OK, feel free to ignore me (which is usually a good idea).

      #!/usr/bin/perl use strict; use warnings; $_ = <<'--'; gregarious foo gregarious foo foo gregarious foo gregarious gregarious foo gregarious foo -- s/(gregarious)/\\underline{$1}/g && s/\\underline\{(gregarious)\}/\\footnote{$1}/; print; __END__ \footnote{gregarious} foo \underline{gregarious} foo foo \underline{gregarious} foo \underline{gregarious} \underline{gregarious} foo \underline{gregarious} foo

      Abigail

        So when the entire file has been slurped into the one variable you can operate on it this way. But if the file is being read a line at a time (implied somewhat by cranberry13 variable naming), then Enlil's method is preferable.