<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:v = 
"urn:schemas-microsoft-com:vml" xmlns:o = 
"urn:schemas-microsoft-com:office:office" xmlns:w = 
"urn:schemas-microsoft-com:office:word" xmlns:m = 
"http://schemas.microsoft.com/office/2004/12/omml"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16640" name=GENERATOR>
<STYLE>@font-face {
        font-family: Calibri;
}
@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.0in 1.0in 1.0in; }
P.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
LI.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
DIV.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-compose
}
.MsoChpDefault {
        mso-style-type: export-only
}
DIV.Section1 {
        page: Section1
}
</STYLE>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]--></HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV dir=ltr align=left><SPAN class=404572122-22052008><FONT face=Arial 
color=#0000ff size=2>Hi,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=404572122-22052008><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=404572122-22052008><FONT face=Arial 
color=#0000ff size=2>Just do it in a Perl-oriented 
style&nbsp;-&nbsp;use&nbsp;</FONT></SPAN><SPAN class=404572122-22052008><FONT 
face=Arial color=#0000ff size=2>the regular expressions:</FONT></SPAN></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial color=#0000ff size=2>#!/usr/bin/perl<BR>use 
warnings;<BR>use strict;</FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2>my $theline = 
"vvvbcd=7wwwbcd=88xxxbcd=999yyybcd=1000zzz";<BR>my $TARGETSTR = 
"bcd=";</FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2>while ($theline =~ 
/($TARGETSTR\d+)/gi) {<SPAN class=404572122-22052008>&nbsp;</SPAN>&nbsp;print 
"$1\n";<SPAN class=404572122-22052008> }</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=404572122-22052008></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=404572122-22052008></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=404572122-22052008>Regards,</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=404572122-22052008></SPAN></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2><SPAN 
class=404572122-22052008>Sergey</SPAN></FONT></FONT></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> 
sanfrancisco-pm-bounces+sergey.fetisov=ask.com@pm.org 
[mailto:sanfrancisco-pm-bounces+sergey.fetisov=ask.com@pm.org] <B>On Behalf Of 
</B>Neil Heller<BR><B>Sent:</B> Thursday, May 22, 2008 3:11 PM<BR><B>To:</B> 
'San Francisco Perl Mongers User Group'<BR><B>Subject:</B> [sf-perl] Plucking 
from a string<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=Section1>
<P class=MsoNormal>I just wrote the code below and was wondering how I could 
make a inner loop A LOT simpler.<o:p></o:p></P>
<P class=MsoNormal>I would appreciate any suggestions.<o:p></o:p></P>
<P class=MsoNormal>Basically the code works like this:<o:p></o:p></P>
<P class=MsoNormal>Given an arbitrary string, that string contains a single 
identifier (in this case &#8220;bcd=&#8221;) followed by a numeric value.<o:p></o:p></P>
<P class=MsoNormal>I would like to pull out the identifier and the value so the 
resulting display is (for example):<o:p></o:p></P>
<P class=MsoNormal>bcd=7<o:p></o:p></P>
<P class=MsoNormal>bcd=88<o:p></o:p></P>
<P class=MsoNormal>bcd=999<o:p></o:p></P>
<P class=MsoNormal>bcd=1000<o:p></o:p></P>
<P class=MsoNormal><o:p>&nbsp;</o:p></P>
<P class=MsoNormal>Neil Heller<o:p></o:p></P>
<P class=MsoNormal><o:p>&nbsp;</o:p></P>
<P class=MsoNormal><o:p>&nbsp;</o:p></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">#! 
usr/bin/perl<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">use 
warnings;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">use 
strict;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">my $counter = 
0;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">my $theline = 
"vvvbcd=7wwwbcd=88xxxbcd=999yyybcd=1000zzz";<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">my $TARGETSTR = 
"bcd=";<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">my $spot = 
0;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">my $done = 
0;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">my 
$fragment;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">my ($inner_done, 
$inner_char, $inner_count);<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">my $NUMERIC = 
"0123456789";<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'"><o:p>&nbsp;</o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">while (!$done) 
{<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; 
$spot = index $theline, $TARGETSTR;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; 
if ($spot == -1) {<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$done = 1;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; } 
else {<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$fragment = substr $theline, $spot;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
print $TARGETSTR;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$inner_done = 0;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$inner_count = 4;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
while (!$inner_done) {<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$inner_char = substr $fragment, $inner_count, 1;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
if ((index $NUMERIC, $inner_char) &gt; -1) {<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
print $inner_char;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$inner_count++;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
} else {<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$inner_done = 1;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
}<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
print "\n";<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$fragment = substr $fragment, 5;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
$theline = $fragment;<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; 
}<o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN 
style="FONT-FAMILY: 'Courier New'">}<o:p></o:p></SPAN></P></DIV></BODY></HTML>