0

I have a string variable as

$variable 

and I have a pattern as like:

/<OPTION [^>]*>\D*([^<]+)/g 

How can I print all the matched strings inside that variable and writing to console a newline character - \n after every matched string with Perl?

2 Answers 2

2

I recommend the use of TreeBuilder to parse HTML. You will gain performance if use XPath or the look_down() function.

By the way:

my @arr = $variable =~ /<OPTION [^>]*>D*([^<]+)/g;
for(0 .. @arr - 1) {
    print $arr[$_] . "\n";
}
Sign up to request clarification or add additional context in comments.

Comments

1

You should use a module for processing HTML data. If you insist on doing it The Wrong Way:

print join("\n", $variable =~ /<OPTION [^>]*>\D*([^<]+)/g), "\n";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.