I was looking at t/op/unshift.t
, and it's a bit strange:
#!./perl print "1..2\n"; @a = (1,2,3); $cnt1 = unshift(a,0); if (join(' ',@a) eq '0 1 2 3') {print "ok 1\n";} else {print "not ok 1\n";} $cnt2 = unshift(a,3,2,1); if (join(' ',@a) eq '3 2 1 0 1 2 3') {print "ok 2\n";} else {print "not ok 2\n";}
There's no @
on the arrays passed to unshift
. That's Perl 1 syntax.
Well, that's because it turns out that every line in that test is verbatim from the Perl 1.0 release test suite. Check out the "blame". I was going to tweak it to use a library for its tests, which would generate nice diagnostics on failure, but given how "1st edition" it is, I don't feel like doing that now.
And the tests pass. But if I put my @a
it fails. (If I put our @a
, it passes.)
No test of the numbers returned?
Re:oh, my
bart on 2009-10-12T07:30:04
But if I put my @a it fails. (If I put our @a, it passes.)
So, what is this, actually? Something like a glob reference? Or worse: a symbolic reference?
It reminds me of the syntax for filehandles.
Re:oh, my
nicholas on 2009-10-12T08:42:47
No, neither glob reference nor symbolic reference. A "regular" package variable. RunDeparse
over it to see what the optree is:$
./perl -Ilib -MO=Deparse t/op/unshift.t
print "1..2\n";
@a = (1, 2, 3);
$cnt1 = unshift(@a, 0);
if (join(' ', @a) eq '0 1 2 3') {
print "ok 1\n";
}
else {
print "not ok 1\n";
}
$cnt2 = unshift(@a, 3, 2, 1);
if (join(' ', @a) eq '3 2 1 0 1 2 3') {
print "ok 2\n";
}
else {
print "not ok 2\n";
}
t/op/unshift.t syntax OKThere's similar obsolete syntax for hashes passed to hash operators without the
%