wind has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't include a HEREDOC within RHS of a Regex
by Anonymous Monk on Jun 15, 2011 at 02:54 UTC | |
by 7stud (Deacon) on Jun 15, 2011 at 06:38 UTC | |
by ikegami (Patriarch) on Jun 15, 2011 at 07:24 UTC | |
|
Re: Can't include a HEREDOC within RHS of a Regex
by ikegami (Patriarch) on Jun 15, 2011 at 07:20 UTC | |
by wind (Priest) on Jun 17, 2011 at 22:32 UTC | |
by ikegami (Patriarch) on Jun 18, 2011 at 00:57 UTC | |
by Anonymous Monk on Jun 18, 2011 at 02:59 UTC | |
|
Re: Can't include a HEREDOC within RHS of a Regex
by Anonymous Monk on Jun 15, 2011 at 02:52 UTC | |
|
Re: Can't include a HEREDOC within RHS of a Regex
by 7stud (Deacon) on Jun 15, 2011 at 01:04 UTC |