On Wed, May 27, 2009 at 06:45, sanket vaidya <[email protected]> wrote:
> Hi all,
>
> Kindly look at the code below:
>
> use warnings;
> use strict;
>
> $_ = 'Welcome to openSUSE 11.0 (X86-64) - Kernel \r (\l).';
>
> my @numbers = split /\D+/;
snip
> Why the first element of @numbers is 'blank'? Kindly explain with example.
snip
For the same reason ",1,2,3" when split with /,/ produces ("", 1, 2,
3). The regex you pass to split is the field separator. The fact
that it finds a field separator before it finds a field data means the
first field is empty. You may find that what you want is a normal
regex like
my @numbers = /(\d+)/g;
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/