Howdy Fellow Monks,
I recently attempted to include a heredoc within the eval'd rhs of a regex. No matter what I attempted, perl died with the following error:
Can't find string terminator "END_TEXT" anywhere before EOF
I've reduced this code to the following example:
use strict; use warnings; my $data = "line1\nfoobar\nline3\n"; $data =~ s{(foo)(bar)}{ my $one = $1; my $two = $2; $one .= <<'END_TEXT'; Insert 1 Insert 2 END_TEXT $one.$two; }e; print $data;
Obviously, one can "fix" the issue by using an ordinary string instead, but I would like y'alls advice concerning this.
Super searching revealed only one thread connected to both heredoc's and regex, but it was unrelated.
Thanks
Update: Anon monk pointed out that it does work when outside of the RHS of the regex:
$data =~ s{(foo)(bar)}{ my $one = $1; my $two = $2; $one .= <<'END_TEXT'; $one.$two; }e; Insert 1 Insert 2 END_TEXT
In reply to Can't include a HEREDOC within RHS of a Regex by wind
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |