Skip to content

Commit 9b32ebd

Browse files
committed
Fix pack '.' format to handle negative positions
The '.' format in pack() was throwing an error for negative positions, blocking 51 tests in pack.t. Perl treats negative positions as 0 (truncate to beginning of string). Changes: - Modified ControlPackHandler.java to treat negative positions as 0 - Removed explicit error throwing for negative positions Test Results: - pack.t: 14673 → 14724 tests running (all tests now run!) - No longer blocks at line 1949 with negative position error - 13811/14724 tests passing (93.8% pass rate) Example that now works: pack('(W)5 (. @2 a)', 0x301..0x305, -3, 'a') Impact: +51 tests unblocked in pack.t
1 parent c71283b commit 9b32ebd

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/main/java/org/perlonjava/operators/pack/ControlPackHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ public int pack(List<RuntimeScalar> values, int valueIndex, int count, boolean h
5050
valueIndex++;
5151
int targetPos = (int) posValue.getDouble();
5252

53-
// DEBUG: '.' format - current size: " + output.size() + ", target position: " + targetPos
54-
53+
// Handle negative positions: treat as 0 (truncate to beginning)
5554
if (targetPos < 0) {
56-
throw new PerlCompilerException("pack: negative position for '.'");
55+
targetPos = 0;
5756
}
5857

5958
int currentSize = output.size();

0 commit comments

Comments
 (0)