SPUG:Split question
Jim Flanagan
jimfl at tensegrity.net
Fri Mar 21 16:38:53 CST 2003
On Fri, 21 Mar 2003, Thane Williams wrote:
> I've often found myself wishing there were an option to split a string
> while retaining the characters you split with. For example:
>
> $string = "a,b,c,d,e,f,";
> @array = split /,/, $string;
> print "@array\n";
>
> Would print
> a, b, c, d, e, f,
> instead of
> a b c d e f
@array = $string =~ /([^,],)/g;
Should get you what you want (in this particular case).
--
::jimfl
http://jimfl.tensegrity.net
mailto:jimfl%40t%65ns%65gr%69ty.n%65t
More information about the spug-list
mailing list