SPUG:Split question

Dan Ebert mathin at mathin.com
Fri Mar 21 16:37:41 CST 2003


You could do:

$string = "a,b,c,d,e,f,";
@array = split /,/, $string;
print join(',', @array), "\n";

-- 
Dan Ebert      <mathin at mathin.com>
-------------------------------------------------------------
Frisbeetarianism (n.), The belief that, when you die, your 
soul goes up on the roof and gets stuck there.

On Fri, 2003-03-21 at 14:26, 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
> 
> Has anyone else wished this? Does anyone have any suggestions? I'd find
> this particularly useful when I'm dividing up big files based on
> complicated strings, and I want to preserve those strings in the chunks.
> _____________________________________________________________
> Seattle Perl Users Group Mailing List  
> POST TO: spug-list at mail.pm.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, U-District, Seattle WA
> WEB PAGE: www.seattleperl.org




More information about the spug-list mailing list