summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--opcode.h2
-rwxr-xr-xopcode.pl2
-rw-r--r--pod/perlfunc.pod4
-rw-r--r--pp_pack.c3
-rwxr-xr-xt/op/pack.t4
5 files changed, 11 insertions, 4 deletions
diff --git a/opcode.h b/opcode.h
index b77c0a831c..62bf30dd15 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 4aacb2d59a..c92aad4433 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 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
diff --git a/pp_pack.c b/pp_pack.c
index 44764541df..6f9abe1dce 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 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 $_