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

[PATCH] Remove implicit split to @_

Thread Next
From:
Michael G Schwern
Date:
July 8, 2009 18:37
Subject:
[PATCH] Remove implicit split to @_
Message ID:
4A5549CE.7090404@pobox.com
Every time I get the warning "Use of implicit split to @_ is deprecated" I
have to go on a hunt to figure out what the hell I did wrong.  perldiag
doesn't help.

       Use of implicit split to @_ is deprecated
           (D deprecated) It makes a lot of work for the compiler when you
           clobber a subroutine's argument list, so it's better if you assign
           the results of a split() explicitly to an array (or list).

Yeah, thanks, I wasn't splitting to @_!

What it really means, in 2009, is that you innocently used split in scalar
context and Perl did some wacky thing and its warning you that it did that
wacky thing.  What it doesn't tell you is what you need to know: that split()
in scalar context does not DWIM.

Rather than fix perldiag, I just removed the LOOOOOOOOONG deprecated
"feature".  How long?  October 17, 1994.  That's right, its a perl 4 feature
that was deprecated in 5.000.  I think 15 years is long enough for everyone to
get the memo.

This makes $count = split / /, $thing; useful again and DWIM.

The diff to disable the feature is surprisingly short:

--- a/pp.c
+++ b/pp.c
@@ -4738,8 +4738,6 @@ PP(pp_split)
        ary = GvAVn(pm->op_pmreplrootu.op_pmtargetgv);
     }
 #endif
-    else if (gimme != G_ARRAY)
-       ary = GvAVn(PL_defgv);
     else
        ary = NULL;
     if (ary && (gimme != G_ARRAY || (pm->op_pmflags & PMf_ONCE))) {

I'm willing to guess there's lots of code inside split() which can now be
removed.  Like that following line checking to see if ary exists outside list
context, which now cannot happen.  But the code for split() is terrifying so
I'm going to do the minimal work.

A warning about use of split in void context should probably also be added.
That now does nothing but regex side effects and that's just a silly use of
split().  Again, I don't have the necessary core hacking bits to do that.


-- 
Insulting our readers is part of our business model.
        http://somethingpositive.net/sp07122005.shtml


--------------080303080404040008040509
Content-Type: application/aegis-patch;
 name="0001-Remove-the-long-1994-deprecated-behavior-of-split.patch"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename*0="0001-Remove-the-long-1994-deprecated-behavior-of-split.patch"

RnJvbSBjOWFjN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vdCB7fS1iYWxhbmNlZCBpbiByZWdleDsgbWFya2VkIGJ5IDwtLSBIRVJFIGlu
IG0vKD97IDwtLSBIRVJFICJ7In0pLyBhdCAtIGxpbmUgMS4KLS0gCjEuNi4yLjQKCg==
--------------080303080404040008040509--

Thread Next


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