cannot find answer in Google, nor figure it out myself. Win7 64bit This is perl 5, version 22, subversion 3 (v5.22.3) built for MSWin32-x86-multi-thread-64int from Active State with modules List::BinarySearch and PAR::Packer installed with cpan
Idea is to edit a text file and add numbers in sorted order. Below is a short version just to reproduce the problem.
Problem: binsearch_pos works when I run the script as pl but fails when I make a standalone EXE out of it.
Code to reproduce:
#!\usr\bin\perl
use strict;
use warnings;
use List::BinarySearch qw/binsearch_pos/;
my @numbers=(0,1,2,4,5,6);
print @numbers;
print "\n";
@numbers=searchandadd(\@numbers,3);
print @numbers;
#search right idx and add value
sub searchandadd {
my ($array, $add) = @_;
my @array = @{$array};
my @sorted = sort { $a <=> $b } @array;
my $idx = binsearch_pos { $a <=> $b } $add, @sorted;
if (0+@sorted == $idx) {
splice @sorted, $idx, 0, $add;
} else {
splice @sorted, $idx, 0, $add
if $sorted[$idx] ne $add;
}
return @sorted;
}
Expected output (from test.pl currently):
C:\Users\timo>test.pl 012456 0123456
EXE creation: pp -o test.exe test.pl
EXE output:
C:\Users\timo>test.exe Scalar found where operator expected at script/test.pl line 17, near "} $add" (Missing operator before $add?) syntax error at script/test.pl line 17, near "} $add" Global symbol "$idx" requires explicit package name (did you forget to declare "my $idx"?) at script/test.pl line 18. Global symbol "$idx" requires explicit package name (did you forget to declare "my $idx"?) at script/test.pl line 19. Global symbol "$idx" requires explicit package name (did you forget to declare "my $idx"?) at script/test.pl line 21. Global symbol "$idx" requires explicit package name (did you forget to declare "my $idx"?) at script/test.pl line 22.
I get same error when EXE made with perl2exe or pp. Could this be because there is some other version of binsearch_pos lurking somewhere?
I'm lost.
BR, Timo