-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Luke Bakken
Sent: Monday, May 01, 2006 2:50 PM
To: Ng, Bill
Cc: perl-win32-users@listserv.ActiveState.com
Subject: Re: Easy One

On 5/1/06, Ng, Bill <[EMAIL PROTECTED]> wrote:
>> Real simple,
>>
>>         I have a string, "$a" for arguments sake, that contains a
single
>> word.  The word will always have exactly 8 characters in it, most
likely
>> something like "ABCD1234".  I need to split this up into two strings
($b

<snip>

>
>if (length $string == 8) # might as well check eh?
>{
>    $string =~ /^([^\d]+)(.*)$/;
>    my ($characterString, $numberString) = ($1, $2);
>}


There is one potential problem with this algorithm, which is that you
aren't checking to make sure that the string actually matches your
regex.  This can result in $1 and $2 containing the values from the last
string that worked instead of being blank or failing, which can be hard
to track down when you start getting different values than what you
expected.


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to