On Mon, Jul 19, 2010 at 08:14, Chandan Kumar <chandan_28...@yahoo.com> wrote:
snip
> my $string = "hi123now456itstimeforsplit789right"
> my @array  = split ( '/(\d+\s)/ ',$string);
snip
> When I run the program ,it prints the whole string. so my assumption is wrong.
>
> please Could some one explain me on this?
snip

The split function splits a string into fields based on a delimiter.
If the delimiter is not present then there is one field.  What you are
describing is a match.  Try this instead:

my @array = $string =~ /(.*?)([0-9]+)\s/g;

What this regex does is match the shortest string that is followed by
one or more digits followed by one whitespace character.  It captures
the stuff before the digits and the digits.  The g on the end causes
it to match as many times as it can, and the fact that the match is in
list context means that the captures will returned as a list.  Note
the use of [0-9] instead of \d.  The \d character class was expanded
in Perl 5.8 to include any Unicode digit character, so it is pretty
much useless now.

You may find [perldoc perlretut][0] and [perldoc perlre][1] useful.

 [0]: http://perldoc.perl.org/perlretut.html
 [1]: http://perldoc.perl.org/perlre.html

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to