I have a simple Perl regex that I need to save as a variable.
If I print it:
print($html_data =~ m/<iframe id="pdfDocument" src=.(.*)pdf/g);
It prints what I want to save, but when trying to save it with:
$link = $html_data =~ m/<iframe id="pdfDocument" src=.(.*)pdf/g;
I get back a '1' as the value of $link. I assume this is because it found '1' match. But how do I save the content of the match instead?
Note the /g to get all matches. Those can't possibly be put into a scalar. You need an array.
my @links = $html_data =~ m/<iframe id="pdfDocument" src=.(.*)pdf/g;
If you just want the first match:
my ($link) = $html_data =~ m/<iframe id="pdfDocument" src=.(.*)pdf/;
Note the parens (and the lack of now-useless /g). You need them to call m// in list context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With