<font face="courier new,monospace">Responding to my own post...<br><br>I just discovered that I can test the defined-ness<br>of $+ (the 'last' extraction) because I wasn't sure<br>if $1 $2... would be _also_ defined, if I specified a list to return into.<br>
<br>hmm, yes, $n are populated regardless of the left hand side<br><br>Thanks<br><br></font><br><div class="gmail_quote">On Fri, May 10, 2013 at 10:16 AM, Mike Stok <span dir="ltr"><<a href="mailto:mike@stok.ca" target="_blank">mike@stok.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">My perl is getting a little rusty, but the first thing I thought of was to check the defined-ness of $1 e.g.<div>
<br></div><div><div class="im"><div>my $line = 'this is stuff in here';</div></div><div>my @patterns = qw / stuff (stuff) stuff/;</div><div class="im"><div>foreach $regex (@patterns) {</div><div> my @capture = ();</div>
<div> print "regex is '$regex' ... ";</div></div><div> if ((@capture = ($line =~ m/$regex/)) && defined $1) {</div><div class="im"><div> print "captured " . scalar @capture . " items \n";</div>
<div> my $i = 0;</div><div> foreach my $item (@capture) {</div><div> print " capture[$i]: '$item'\n";</div><div> $i++;</div><div> }</div><div> } else {</div>
<div> print "nothing captured\n";</div><div> }</div><div>} </div></div></div><div><br></div><div>I'm sure there's some problem with that though...</div><div><br></div><div>Mike</div><div><div class="im">
<br><div><div>On 2013-05-10, at 10:06 AM, Fulko Hew <<a href="mailto:fulko.hew@gmail.com" target="_blank">fulko.hew@gmail.com</a>> wrote:</div><br><blockquote type="cite"><span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">my $line = 'this is stuff in here';</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">my @patterns = qw / stuff (stuff) /;</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">foreach $regex (@patterns) {</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> my @capture = ();</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> print "regex is '$regex' ... ";</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> if (@capture = ($line =~ m/$regex/)) {</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> print "captured " . scalar @capture . " items \n";</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> my $i = 0;</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> foreach my $item (@capture) {</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> print " capture[$i]: '$item'\n";</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> $i++;</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> }</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> } else {</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> print "nothing captured\n";</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none"> }</span><br style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<span style="font-family:'courier new',monospace;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">}</span></blockquote>
</div><br></div><span class="HOEnZb"><font color="#888888"><div>
<span style="border-collapse:separate;border-spacing:0px;font-size:12px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">-- </div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">Mike Stok <<a href="mailto:mike@stok.ca" target="_blank">mike@stok.ca</a>></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
<a href="http://www.stok.ca/~mike/" target="_blank">http://www.stok.ca/~mike/</a></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">
The "`Stok' disclaimers" apply.</div><div><br></div><div><br></div><br></span>
</div>
<br></font></span></div></div></blockquote></div><br>