Issue with eval_in_page - Trying to interpolate an array

假装没事ソ 提交于 2019-12-12 03:56:20

问题


my @para_text = $mech->xpath('/html/body/form/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/table/tbody/tr[3]/td/div/div/div', type => $mech->xpathResult('STRING_TYPE'));
#BELOW IS JUST TO MAKE SURE THE ABOVE CAPTURED THE CORRECT TEXT 
print "Look here: @para_text";

$mech->click_button( id => "lnkHdrreplyall");
$mech->eval_in_page('document.getElementsByName("txtbdy")[0].value = "@para_text"');

In the last line of my code I need to put the contents of the @para_text array as the text to output into a text box on a website however from the "document" till the end of the line it needs to be surrounded by ' ' to work. Obviously this doesnt allow interpolation as that would require " " Any ideas on what to do?


回答1:


To define a string that itself contains double quotes as well as interpolating variable values, you may use the alternative form of the double quote qq/ ... /, where you can choose the delimiter yourself and prevent the double quote " from being special

So you can write

$mech->eval_in_page(qq/document.getElementsByName("txtbdy")[0].value = "@para_text"/)


来源:https://stackoverflow.com/questions/43142971/issue-with-eval-in-page-trying-to-interpolate-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!