Thank you Gaal!

Once again, I constantly forget the RTFM directive. ‘split’ (and ‘join’) are so 
intuitive that I never bothered to lookup the doc.

Thank all of you

Meir

 

From: [email protected] [mailto:[email protected]] On Behalf Of 
Gaal Yahas
Sent: יום ב 04 מרץ 2013 15:35
To: Perl in Israel
Subject: Re: [Israel.pm] Inconsistent 'split' behavior

 

Try split /\t/, $str, -1. See perldoc -f split for more details.

On Mon, Mar 4, 2013 at 2:32 PM, Meir Guttman <[email protected]> wrote:

Hello Perlers.
I recently discovered what seems to me an inconsistent behavior when
splitting Tab-separated-Values (TSV). If the last column has an empty
string, no empty string is added to the 'split' array. However, when a
center column has an empty string (simply two consecutive tab-characters) it
is conserved.
Is that behavior as it should be?
Here is a small script to show it:

use strict;
use warnings;
use Data::Dumper::AutoEncode; # This one supports Unicode

my $tsv_line = "col_1\tcol_2\tcol_3";
print "Regular TSV string: '$tsv_line'\n";
my @split_line = split("\t", $tsv_line);
print eDumper(\@split_line), "\n";

my $missing_col_tsv_line = "col_1\tcol_2\t";
print "missing LAST column TSV string: '$missing_col_tsv_line'\n";
my @split_missing_col_line = split("\t", $missing_col_tsv_line);
print eDumper(\@split_missing_col_line), "\n";

my $missing_middle_col = "col_1\t\tcol_3";
print "missing MIDDLE column TSV string: '$missing_middle_col'\n";
my @split_missing_middle_col = split("\t", $missing_middle_col);
print eDumper(\@split_missing_middle_col), "\n";

Meir

_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl





 

-- 
Gaal Yahas <[email protected]>
http://gaal.livejournal.com/ 

_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to