I am extremely thankful to you for your help. I always loved your way of teaching and explaining the code bit by bit.
One more question I searched the google for "HTH" abbreviation but didn't find anything. Can you tell me what does it mean? Thanks, Sara, :)) ----- Original Message ----- From: Charles K. Clarkson <[EMAIL PROTECTED]> To: 'Sara' <[EMAIL PROTECTED]>; 'org' <[EMAIL PROTECTED]> Sent: Wednesday, July 09, 2003 6:30 AM Subject: RE: split function problem. > Sara <[EMAIL PROTECTED]> wrote: > : > : An input string like; > : > : $name_with_id = "Deiley, Sara Jr., 1234"; > : > : another example could be > : > : $name_with_id = "DEILEY SARA, Jr,. 123"; > : > : Two things are for sure in it always. > : > : 1- First part contains the alphabets (caps or small) with any > : number of commas and periods (full stops) in between or at the end. > : > : and then always a white space, followed by: > : > : 2- the last part contains the digit/number which could be 2 - > : 5 digits long. > > > : I am trying this; > : > : $name_with_id = "Deiley, Sara Jr., 1234"; > : > : split (/[^\d]+/, $name_with_id) = ($name,$id); > > [^\d]+ will match anything that is *not* a > digit. and appears more that one time in the > search string. In our example string, it splits > on: "Deiley, Sara Jr., ". All of which is not a > digit. > > To find the last part we could use: \d{2,5} > William of Occam gave pretty good advice: > "Entities should not be multiplied unnecessarily." > > > : print "name: $name and ID: $id"; > : > : Error: Can't modify split in scalar assignment at line 3; > > Unlike 'substr', split can only be on the right > side of an equation. If you set split equal to > something, you'll get the error above. So this > would seem more logical: > > my ($name,$id) = split (/\d{2,5}/, $name_with_id); > > The problem is that split discards the > part we're looking for: \d{2,5} unless we > place it in parenthesis. > > my( $name, $id ) = split / (\d{2,5})/, $name_with_id; > > This should throw away the space and keep the > digits: > > use strict; > use warnings; > use Data::Dumper; > > my $name_with_id = "Deiley, Sara Jr., 1234"; > > print Dumper [ split / (\d{2,5})$/, $name_with_id ]; > > __END__ > > HTH, > > Charles K. Clarkson > -- > Head Bottle Washer, > Clarkson Energy Homes, Inc. > Mobile Home Specialists > 254 968-8328 > > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]