develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #118879] split() in do{} and eval{} blocks lacks implicit limit

Thread Previous
From:
James E Keenan via RT
Date:
July 11, 2013 21:55
Subject:
[perl #118879] split() in do{} and eval{} blocks lacks implicit limit
Message ID:
rt-3.6.HEAD-2552-1373579686-1594.118879-15-0@perl.org
On Thu Jul 11 11:35:33 2013, galama wrote:
> perldoc split says: "when assigning to a list, if LIMIT is omitted (or
> zero), then LIMIT is treated as though it were one larger than the
> number of variables in the list".
> 
> Apparently, this is not the case within a do{} or eval{} block:
> 
> 
> use Data::Dumper;
> 
> # implicit limit = 3 in accordance with the docs
> # -> empty trailing field preserved
> ($a, $b) = split /,/, 'a,';
> print Dumper($b);  # empty string
> 
> # implicit limit = 0 contrary to the docs
> # -> empty trailing field stripped
> ($a, $b) = do { split /,/, 'a,' };
> print Dumper($b);  # undef
> 
> ($a, $b) = eval { split /,/, 'a,' };
> print Dumper($b);  # undef
> 
> __END__
> 
> 

Confirmatory code:

$ perl -MData::Dumper -E '$Data::Dumper::Indent=0;($a, $b) = split /,/,
"a,"; say Dumper ([$a,$b]);'
$VAR1 = ['a',''];

$ perl -MData::Dumper -E '$Data::Dumper::Indent=0;($a, $b) = do { split
/,/, "a," }; say Dumper ([$a,$b]);'
$VAR1 = ['a',undef];

$ perl -MData::Dumper -E '$Data::Dumper::Indent=0;($a, $b) = eval {
split /,/, "a," }; say Dumper ([$a,$b]);'
$VAR1 = ['a',undef];


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=118879

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About