develooper Front page | perl.perl5.porters | Postings from February 2003

[PATCH] unpack(TEMPLATE) default to $_

Thread Next
From:
Chip Salzenberg
Date:
February 17, 2003 14:58
Subject:
[PATCH] unpack(TEMPLATE) default to $_
Message ID:
20030217225828.GA2321@perlsupport.com
In creating a neat map {} expression today, I had to write "$_"
explicitly because unpack wouldn't default to $_.  That's Not Right.

Here's a patch to make unpack default to $_ if given only a template.

PS: If you think multi-parameter operators shouldn't default to $_, I
    can only answer: "split".  :-)

PPS: I can do the p4 commit if the patch is acceptable.

==== //depot/perl/opcode.h#83 - /u/src/perl/current/opcode.h ====
@@ -1615,5 +1615,5 @@
 	0x00028404,	/* helem */
 	0x00048801,	/* hslice */
-	0x00022800,	/* unpack */
+	0x00122800,	/* unpack */
 	0x0004280d,	/* pack */
 	0x00222808,	/* split */
==== //depot/perl/opcode.pl#99 - /u/src/perl/current/opcode.pl ====
@@ -627,5 +627,5 @@
 # Explosives and implosives.
 
-unpack		unpack			ck_fun		@	S S
+unpack		unpack			ck_fun		@	S S?
 pack		pack			ck_fun		mst@	S L
 split		split			ck_split	t@	S S S
==== //depot/perl/pod/perlfunc.pod#364 - /u/src/perl/current/pod/perlfunc.pod ====
@@ -5945,8 +5945,12 @@
 =item unpack TEMPLATE,EXPR
 
+=item unpack TEMPLATE
+
 C<unpack> does the reverse of C<pack>: it takes a string
 and expands it out into a list of values.
 (In scalar context, it returns merely the first value produced.)
 
+If EXPR is omitted, splits the C<$_> string.
+
 The string is broken into chunks described by the TEMPLATE.  Each chunk
 is converted separately to a value.  Typically, either the string is a result
==== //depot/perl/pp_pack.c#33 - /u/src/perl/current/pp_pack.c ====
@@ -1607,5 +1607,6 @@
 {
     dSP;
-    dPOPPOPssrl;
+    SV *right = (MAXARG > 1) ? POPs : GvSV(PL_defgv);
+    SV *left = POPs;
     I32 gimme = GIMME_V;
     STRLEN llen;
==== //depot/perl/t/op/pack.t#75 - /u/src/perl/current/t/op/pack.t ====
@@ -7,5 +7,5 @@
 }
 
-plan tests => 5826;
+plan tests => 5827;
 
 use strict;
@@ -996,2 +996,4 @@
 ok(pack('u2', 'AA'), "[perl #8026]"); # used to hang and eat RAM in perl 5.7.2
 
+$_ = 'A';
+ok(unpack('c') == 65); # defaulting to $_



-- 
Chip Salzenberg         - a.k.a.  -        <chip@pobox.com>
         "It furthers one to have somewhere to go."

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