SPUG:Split question

Pommert, Daniel Daniel.Pommert at VerizonWireless.com
Fri Mar 21 16:36:20 CST 2003


You need to provide the third parameter to split and it needs to either be a
very large number or a negative number.  Otherwise, as per the
documentation, split will intentionally strip off the trailing empty fields.

So, you example should read:

$string = "a,b,c,d,e,f,";
@array = split /,/, $string, -1;
print "@array\n";

-- Daniel Pommert

-----Original Message-----
From: Thane Williams [mailto:thane at fastmail.fm]
Sent: Friday, March 21, 2003 2:26 PM
To: spug-list at pm.org
Subject: SPUG:Split question


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