[Israel.pm] How to "split" but keep the delimiter

Oron Peled oron at actcom.co.il
Mon Dec 6 03:25:43 PST 2004


On Monday 06 December 2004 12:48, Yossi.Itzkovich at ecitele.com wrote:
> I know I can do it without "split", but still, by using split, how can I
> still leave the delimiter in the returned list ?

Use parenthesis in the pattern and you'll get it as additional
elements. Example:
 $mystring = "words42with24numbers12as34separators";
 @out = split(/(\d+)/, $mystring);
Would return 9 elements.

Read 'perldoc -f split' carefully.

-- 
Oron Peled                             Voice/Fax: +972-4-8228492
oron at actcom.co.il                  http://www.actcom.co.il/~oron
ICQ UIN: 16527398

"It's almost like we're doing Windows users a favor by charging them money
for something they could get for free, because they get confused otherwise."
 - Larry Wall.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
Url : http://perl.org.il/pipermail/perl/attachments/20041206/bb915768/attachment.pgp 


More information about the Perl mailing list