diff options
-rw-r--r-- | opcode.h | 2 | ||||
-rwxr-xr-x | opcode.pl | 2 | ||||
-rw-r--r-- | pod/perlfunc.pod | 4 | ||||
-rw-r--r-- | pp_pack.c | 3 | ||||
-rwxr-xr-x | t/op/pack.t | 4 |
5 files changed, 11 insertions, 4 deletions
@@ -1614,7 +1614,7 @@ EXT U32 PL_opargs[] = { 0x00000248, /* rv2hv */ 0x00028404, /* helem */ 0x00048801, /* hslice */ - 0x00022800, /* unpack */ + 0x00122800, /* unpack */ 0x0004280d, /* pack */ 0x00222808, /* split */ 0x0004280d, /* join */ @@ -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 355ada86f7..7fed9c0239 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<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, 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<pack>, or the bytes of the string represent a C structure of some @@ -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 a4c5db01d2..1c971c66ce 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 $_ |