Thanks. This worked.
On 1/18/15 12:28 PM, Jim Gibson wrote:
On Jan 18, 2015, at 9:03 AM, Mike <ekimduna...@gmail.com> wrote:
I was able to find match extraction in the perldoc.
Here is a snippet of what I have.
my $insult = ( $mech->text =~ m/Insulter\ (.*)\ Taken/ );
print "$insult\n";
But $insult is being populated with: 1
It should be populated with text. Can anyone tell me what I'm doing wrong here?
Your error is assigning the return value of the regular expression in a scalar
context. In scalar context, a regular expression returns true or false
indicating a match (or not). In array context, however, it returns the captured
subexpressions as a list.
Try forcing the assignment into array context:
my( $insult ) = ( $mech->text =~ m/Insulter\ (.*)\ Taken/ );
You can also use the capture variables $1, $2, $3, etc., which will contain the
captured subexpressions:
my $insult;
if( $mech->text =~ m/Insulter\ (.*)\ Taken/ ) ) {
$insult = $1;
}
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/