Dear fellow monks,
Please consider the following:
$code = 'while (<>) {'; $code .= 'if (/'; $code .= join ('/ && /', @regexen); $code .= '/) {' $code .= ' print $_;' $code .= '}} '; eval $code; die "Error: $@\n Code:\n$code\n" if ($@);
I would like to ask a specific and a general question:
Specifically, I am interested in performance: if matching many patterns, how does qr// + while-loop perform, compared with an eval of a built string containing while-loop + same patterns 'hard-coded' (as in the above example).
And more generally: how do people use eval string? Are there cases that really need it? (but I would also like to invite the more strange uses.)
I do understand that it should only be used on trusted strings.
My experience with eval string is
limited, and I hope to learn from the way others are using this clearly powerful technique.
Thanks
In reply to eval string possibilities by erix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |