0

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

  • Works fine on Ubuntu 16.10, perl version 5.24.1 – Håkon Hægland Apr 19 '17 at 12:10
  • 1
    Oh dear, I was afraid of this. Needed to go down from Perl 5.24.1 64bit to 32bit and finally to 5.22.3 32bit to get cpan to compile pp, which I thought was the best shot to solve this after perl2exe gave same error. Unfortunately I need to stick with Windows perl as the server where I want the tool to run is a Windows. I need to go down the path to test Strawberry perl I guess. And I picked perl for this "as it's the easiest to get the job done". Life is.. – Timo Karhu Apr 19 '17 at 12:17
  • 1
    My God! I stared my example and remembered my first pp EXE attemps whining about shebang character where I had linux style forward slashes. Changed them to backslashes and got rid of it. While staring at sheband I thought, does it make any change to put a real path there, in my case c:\perl\bin. No other change than now BOTH work pl and pp'd test.exe. I knew it was something simple. Why? No idea and I'm fine having the tool working as EXE now!! – Timo Karhu Apr 19 '17 at 13:55
  • No, It wasn't the shebang. Adding -x to pp parameters seems to have resolved the issue. Why? No idea.. e.g "pp -x -o test.exe test.pl" works. – Timo Karhu Apr 19 '17 at 14:08

0 Answers0