<div dir="ltr">Hi Madision,<br><br>I'm not sure I get what you're doing<br><br>The foreach doesn't return a list for each iteration (which is what you're doing by trying to assign to (my $variable, my $value). It returns one scalar for each iteration of the loop. The foreach just iterates over an array. If you do a regex in a foreach with /g it returns what's captured as a list but you only get key OR value for each iteration.<br>
<br>Why would you not just do this?<br><br>(Apologies for the formatting)<br><br><span style="font-family: courier new,monospace;">my $results_page = qq/</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <input name="varname" type="hidden" value="varval"></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <input name="varname2" type="hidden" value="varval2"></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">/;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">my %results = ();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">while ( <br> $results_page =~ <br> /<input name="(.*?)" type="hidden" value="(.*?)">/gs<br>
) {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> my ($var,$val) = ($1, $2);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> print "Storing: [$var]\t->\t[$val]\n";</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> $results{$var}=$val;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;">
<br>I don't see how the saved line is of any benefit in this instance.<br><br>Further to this, regexes to parse html isn't ideal. There's any number of changes in the HTML that could break this (ordering of the attributes, case of the tags/attributes, using single instead of double quotes to delimit the values, etc...)<br>
<br>D<br><br><br><div class="gmail_quote">On Fri, Aug 1, 2008 at 12:17 PM, Madison Kelly <span dir="ltr"><<a href="mailto:linux@alteeve.com">linux@alteeve.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Fulko Hew wrote:<div><div></div><div class="Wj3C7c"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
On Fri, Aug 1, 2008 at 10:50 AM, Madison Kelly <<a href="mailto:linux@alteeve.com" target="_blank">linux@alteeve.com</a> <mailto:<a href="mailto:linux@alteeve.com" target="_blank">linux@alteeve.com</a>>> wrote:<br>
<br>
As an expansion to my earlier question on assigning values to new<br>
variables directly from a regular expression; I want to now use a<br>
similar technique to populate a 'foreach' loop.<br>
<br>
<br>
<br>
... snip ...<br>
<br>
However, this doesn't:<br>
<br>
my $results_page=$agent->content;<br>
my %results=();<br>
foreach (my $variable, my $value) ($results_page=~/<input<br>
name="(.*?)" type="hidden" value="(.*?)">/gs)<br>
<br>
^^<br>
<br>
How about... you forgot the equal sign for the assignment!<br>
</blockquote>
<br></div></div>
Doesn't look like this is the case (tried it to be sure), or if it is, I am note sure where the '=' would go for the assignment. As I understand the 'for'/'foreach' syntax is that is automatically pops a value off the array per iteration.<br>
<br>
Not that I am not often wrong. :)<div><div></div><div class="Wj3C7c"><br>
<br>
Madi<br>
_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="mailto:dave.s.doyle@gmail.com">dave.s.doyle@gmail.com</a><br>
</div>