I have outputs from a device I need to test and mostly the response is one line, but sometimes it is two lines. Which I handle with a simple regex parsing one or two lines
if ($prompt =~ /(\s.*?)\r\n(.*)/)
{
Note('Multiline '.$string);
TestPrompt($string, $1);
TestPrompt($string, $2);
}
else
{
TestPrompt($string, $prompt);
}
But what if the response is more than two lines? This code cannot handle the additional lines and I’d like to be robust in my design. Is there a way to capture from regex for use in a foreach?
Why not use the
splitfunction instead to do this? Here is a link to some examples of usage. For your example, why not do this: