New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split to list assignment in scalar context #11740
Comments
From ambrus@math.bme.huCreated by ambrus@math.bme.huThis command gives an unexpected result: $ perl -wE 'say scalar(($_x, $_y) = split "/", "one/two/three/four/five");' One would naively think it should return 5, just like this command: $ perl -wE 'say scalar((@_x) = split "/", "one/two/three/four/five");' for the split returns a list of five strings and the list assignment returns The surprising behaviour of the first command is actually sort-of documented When assigning to a list, if LIMIT is omitted, or zero, Perl supplies a So in the first command, split("/", $s) is silently changed to split("/", I propose that you change split to use this implicit limit only when this This came up in the real world by the way, and I was utterly baffled by it By the way, the bug still happens if you add an explicit limit of 0, eg. $ perl -wE 'say scalar(($_x, $_y) = split "/", "one/two/three/four/five", which is completely against what the docs say, as noted by core bug #3247 Also, the bug is still present in perlblead as of a few weeks ago. -- Perl Info
|
From @jkeenanOn Tue Nov 08 14:37:05 2011, b_jonas wrote:
But we also need to take into account the documentation for the 'scalar' ##### My hunch is that in your first case above, the "final element evaluated Thank you very much. |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Mon Dec 05 18:08:31 2011, jkeenan wrote:
But list assignment in scalar context returns the number of elements on That’s separate from the comma operator in scalar context.
-- Father Chrysostomos |
From @tamiasOn Mon, Dec 05, 2011 at 06:08:32PM -0800, James E Keenan via RT wrote:
That paragraph is not relevant here. The argument to scalar in the first
No, it's 3, the number of elements in ( qw| one two three/four/five | ). perldoc -f split The LIMIT parameter can be used to split a line partially ($login, $passwd, $remainder) = split(/:/, $_, 3); When assigning to a list, if LIMIT is omitted, or zero, Perl To get 5 instead, specify a limit of -1: $ perl -wE 'say scalar(($_x, $_y) = split "/", "one/two/three/four/five", -1);' This is not a bug. Ronald |
From @cpansproutOn Mon Dec 05 18:33:01 2011, rjk@tamias.net wrote:
It’s a wishlist item. -- Father Chrysostomos |
From ambrus@math.bme.huOn Tue, Dec 6, 2011 at 3:43 AM, Father Chrysostomos via RT
Agreed with Father Chrysostomos. It's not a definite bug, but it's a Ambrus |
From ambrus@math.bme.huSee also ticket #118879 . |
From [Unknown Contact. See original ticket]See also ticket #118879 . |
Migrated from rt.perl.org#103212 (status was 'open')
Searchable as RT103212$
The text was updated successfully, but these errors were encountered: