[tpm] YARE (yet another regex) question

Madison Kelly linux at alteeve.com
Fri Aug 1 07:50:53 PDT 2008


   As an expansion to my earlier question on assigning values to new 
variables directly from a regular expression; I want to now use a 
similar technique to populate a 'foreach' loop.

   Specifically; This works:

# WWW::Mechanize object.
my $processing_page=$agent->content;
foreach my $cookie ($processing_page=~/document.cookie="(.*?)"/gs)
{
	my ($variable, $value, $path)=$cookie=~/(.*?)=(.*?); path=(.*?);/;
	print "Setting cookie: [$variable=$value, $path under 
$$conf{nexxia}{cookie_domain}]\n";
	$agent->cookie_jar->set_cookie(0, $variable, $value, $path, 
$$conf{nexxia}{cookie_domain});
}

   However, this doesn't:

my $results_page=$agent->content;
my %results=();
foreach (my $variable, my $value) ($results_page=~/<input name="(.*?)" 
type="hidden" value="(.*?)">/gs)
{
	print "Storing: [$variable]\t->\t[$value]\n";
	$results{$variable}=$value;
}

   I'd like to grab two variables into a foreach loop. Perhaps this 
doesn't work at all, regardless of the source?

Thanks, as always!

Madi


More information about the toronto-pm mailing list