Perl 5 is Perl 1. And TAP is 22.

nicholas on 2009-10-11T20:24:57

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.


oh, my

slanning on 2009-10-11T21:56:11

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. Run Deparse 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 OK

There's similar obsolete syntax for hashes passed to hash operators without the %