From: Chip Salzenberg Date: Wed, 19 Feb 2003 03:54:45 +0000 (+0000) Subject: Support one-parameter unpack(), which unpacks $_. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=13dcffc60adeca175c32a1ea11ec8756d4853ad2;p=p5sagit%2Fp5-mst-13.2.git Support one-parameter unpack(), which unpacks $_. p4raw-id: //depot/perl@18751 --- diff --git a/opcode.h b/opcode.h index b77c0a8..62bf30d 100644 --- a/opcode.h +++ b/opcode.h @@ -1614,7 +1614,7 @@ EXT U32 PL_opargs[] = { 0x00000248, /* rv2hv */ 0x00028404, /* helem */ 0x00048801, /* hslice */ - 0x00022800, /* unpack */ + 0x00122800, /* unpack */ 0x0004280d, /* pack */ 0x00222808, /* split */ 0x0004280d, /* join */ diff --git a/opcode.pl b/opcode.pl index 4aacb2d..c92aad4 100755 --- a/opcode.pl +++ b/opcode.pl @@ -626,7 +626,7 @@ hslice hash slice ck_null m@ H L # 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 join join or string ck_join mst@ S L diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 355ada8..7fed9c0 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -5944,10 +5944,14 @@ If LIST is omitted, uses C<$_>. =item unpack TEMPLATE,EXPR +=item unpack TEMPLATE + C does the reverse of C: 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, unpacks 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 of C, or the bytes of the string represent a C structure of some diff --git a/pp_pack.c b/pp_pack.c index 4476454..6f9abe1 100644 --- a/pp_pack.c +++ b/pp_pack.c @@ -1606,7 +1606,8 @@ Perl_unpack_str(pTHX_ char *pat, register char *patend, register char *s, char * PP(pp_unpack) { dSP; - dPOPPOPssrl; + SV *right = (MAXARG > 1) ? POPs : GvSV(PL_defgv); + SV *left = POPs; I32 gimme = GIMME_V; STRLEN llen; STRLEN rlen; diff --git a/t/op/pack.t b/t/op/pack.t index a4c5db0..1c971c6 100755 --- a/t/op/pack.t +++ b/t/op/pack.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 5826; +plan tests => 5827; use strict; use warnings; @@ -995,3 +995,5 @@ foreach my $template (qw(A Z c C s S i I l L n N v V q Q j J f d F D u U w)) { ok(pack('u2', 'AA'), "[perl #8026]"); # used to hang and eat RAM in perl 5.7.2 +$_ = 'A'; +ok(unpack('c') == 65); # defaulting to $_