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() in do{} and eval{} blocks lacks implicit limit #13104
Comments
From agalama@mailfish.deperldoc split says: "when assigning to a list, if LIMIT is omitted (or Apparently, this is not the case within a do{} or eval{} block: use Data::Dumper; # implicit limit = 3 in accordance with the docs # implicit limit = 0 contrary to the docs ($a, $b) = eval { split /,/, 'a,' }; __END__ Flags: This perlbug was built using Perl 5.14.4 in the Fedora build system. Site configuration information for perl 5.14.4: Configured by Red Hat, Inc. at Thu Apr 11 12:56:04 UTC 2013. Summary of my perl5 (revision 5 version 14 subversion 4) configuration: Platform: Locally applied patches: @INC for perl 5.14.4: Environment for perl 5.14.4: PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/xxx/.local/bin:/home/xxx/bin |
From @jkeenanOn Thu Jul 11 11:35:33 2013, galama wrote:
Confirmatory code: $ perl -MData::Dumper -E '$Data::Dumper::Indent=0;($a, $b) = split /,/, $ perl -MData::Dumper -E '$Data::Dumper::Indent=0;($a, $b) = do { split $ perl -MData::Dumper -E '$Data::Dumper::Indent=0;($a, $b) = eval { |
The RT System itself - Status changed from 'new' to 'open' |
From @rjbs* Anand Galama <perlbug-followup@perl.org> [2013-07-11T14:35:33]
I imagine the easiest and more appropriate fix is to say "when immediately -- |
From @cpansproutOn Sun Jul 14 05:44:46 2013, perl.p5p@rjbs.manxome.org wrote:
I always thought this was just an optimisation and it was only But as the OP points out, it can change undef into an empty string. Do we want to make it so that this optimisation is purely an optimisation? -- Father Chrysostomos |
From agalama@mailfish.deOn Sun Jul 14 05:44:46 2013, perl.p5p@rjbs.manxome.org wrote:
Thanks, this just lead me to another even simpler example. :-) ($n, $a, $b) = (1, split /,/, 'a,'); This also makes $b undef just like in the do{} and eval{} case but I |
From @ap* Father Chrysostomos via RT <perlbug-followup@perl.org> [2013-07-14 16:00]:
I think it should be. But how to go about it? Do you want to expose this capability in some This is also a very wide-spread usage, undoubtedly relied on unwittingly Off the cuff the only thing I can think of is for `split` to return (No doubt this would also clean up code that is inadvertently buggy * Anand Galama via RT <perlbug-followup@perl.org> [2013-07-15 05:55]:
Does this do it for you? Inline Patchdiff --git i/pod/perlfunc.pod w/pod/perlfunc.pod
index 18ecd40..c108733 100644
--- i/pod/perlfunc.pod
+++ w/pod/perlfunc.pod
@@ -6959,8 +6959,9 @@ produces the output 'a:b:c', but the following:
produces the output 'a:b:c:::'.
In time-critical applications, it is worthwhile to avoid splitting
-into more fields than necessary. Thus, when assigning to a list,
-if LIMIT is omitted (or zero), then LIMIT is treated as though it
+into more fields than necessary. Thus, when the right-hand side of
+a list assignment consists only of a C<split>, and LIMIT is omitted
+(or zero), then LIMIT is treated as though it
were one larger than the number of variables in the list; for the
following, LIMIT is implicitly 3: |
From @ap* Aristotle Pagaltzis <pagaltzis@gmx.de> [2013-07-16 03:00]:
(By which I mean code that’s currently written to expect it will get |
From @cpansproutOn Mon Jul 15 17:58:37 2013, aristotle wrote:
An explicit third argument does that, does it not?
Instead of explaining how the optimisation works, just state the Then we can fix #103212 as well.
If the deprecation warning could be spelt ‘Use of uninitialized value’, Or do you mean one for which defined($_) returns true, but which is But how much code is really relying on that single empty string? $ ./perl -Ilib -e '($a,$b,$c,$d,$e,$f) = split //, "abc"; warn
-- Father Chrysostomos |
From @ap* Father Chrysostomos via RT <perlbug-followup@perl.org> [2013-07-16 03:15]:
No? Now I’m not sure we’re even talking about the same thing. An explicit third argument tells `split` to stop splitting at the given The user can omit the third argument (and trip up the optimisation) to With the current interface there is no way for the user to ask for one What I understood you to be asking is whether perl -E '($n, $a, $b) = (1, split /,/, "a,"); say 1 if defined $b' should both be silent (where currently the latter isn’t) while at the In other words, should `split` be able to do something (stop splitting Now when you deparse `($a,$b) = split//`, it actually says this: ($a, $b) = split(//, $_, 3); If the optimisation were made transparent, then deparsing the `split` Either the optimisation would have to trigger in some other way (within ($a, $b) = split(//, $_); If that is not the case, and the optimisation is reflected in the op
I am *not* proposing to deprecate the absence of a warning by warning
Yes, that is what I was thinking of. Very specifically the case of `defined $trailing_field` is what would Currently that expression returns true, after the change it would return Other uses of $trailing_field are murkier in whether they will cause any
I don’t know. I’m not worried about the total amount in and of itself. It can also construed a documented and advertised feature if you read But I suppose running a CPAN smoke using the transparent optimisation PS.: it is irritating how much verbiage it takes to talk clearly about Regards, |
From agalama@mailfish.deOn Mon Jul 15 17:58:37 2013, aristotle wrote:
Hmmm: ($a, $b) = split /,/, 'a,'; # ('a', '') as expected The second one would have to be changed if you change the docs your way. Interestingly: ($a, $b) = @a[0,1] = split /,/, 'a,'; # ('a', undef) I am sure Schrödinger would have called his cat "Split". :-) |
From @cpansproutOn Mon Jul 15 19:59:07 2013, aristotle wrote:
I see what you are saying. That would require yet some other syntax. I
If it is just an optimisation, then the calling code can’t know whether
If we change the behaviour, then we will obviously have to change the -- Father Chrysostomos |
Migrated from rt.perl.org#118879 (status was 'open')
Searchable as RT118879$
The text was updated successfully, but these errors were encountered: