Am I missing something?
[EMAIL PROTECTED] nick] cat split_test.pl
#!/usr/bin/perl -w
while(my $line = <>) {
my @F = split( ',', $line );
print "[EMAIL PROTECTED] has ", scalar(@F), " entries\n";
}
[EMAIL PROTECTED] nick] perl split_test.pl
A,B,C
@F has 3 entries
A,B,C,D,E,F
@F has 6 entries
A,B,C,D,,
@F has 6 entries
A,B,C,,,
@F has 6 entries
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Ken Gosier
Sent: Friday, April 30, 2004 5:44 PM
To: [EMAIL PROTECTED]
Subject: [Boston.pm] make split return empty entries?
Hi, question from a most-times lurker. I'm reading in a
bunch of lines of the form
A,B,C,D,E,F
with the split statement:
my @F = split ',', $line;
However, sometimes the trailing fields are blank:
A,B,C,,,
In this case, @F will only contain 3 entries, since split
will not count the trailing null entries. This screws up my
code later on. It'd be much easier to assume @F always has
6 entries.
By reading perldoc -f split, I wasn't able to find a way to
make split count those entries. Is there a way to make
split count trailing null entries?
Many thanks for any help, I can work my code around this,
but it's a bit of a pain in the @$$...
=====
Ken Gosier
[EMAIL PROTECTED]
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm