#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2

    Could someone convert this perl to an exe?


    I have a perl script and I've tried many programs but for some reason nothing happens when I type the command. Could someone convert the below perl script to an exe please?

    Code:
    #!/usr/local/bin/perl -w
    #
    # Script for removing units outside a specified area and time from the 
    # *.mis files of SH3.
    # Written by LGN1, March 2010
    #
    
    use strict;
    # SCR, RND, or LND layer
    print "SCR, RND, or LND? (s/r/l)";
    my $dlayer = <>;
    chomp($dlayer);
    my $layer = " ";
    if ($dlayer eq "r") {$layer = "RND"}
    else {$layer = "LND"};
    if ($dlayer eq "s") {$layer = "SCR"};
    open(READF,"Campaign_$layer.mis")
        or die "Error while opening the file: $!\n";
    
    print "Start date (YYYYMMDD) (default 19390101): ";
    my $startdate = <>;
    if ($startdate eq "\n") {$startdate = 19390101;print "Default: $startdate\n"}
    else {chomp ($startdate)};
    print "End date (YYYYMMDD) (default 19451231): ";
    my $enddate = <>;
    if ($enddate eq "\n") {$enddate = 19451231;print "Default: $enddate\n"}
    else {chomp ($enddate)};
    print "Upper longitude[km] (default: 5000): ";
    my $upperlong = <>;
    if ($upperlong eq "\n") {$upperlong = 5000;print "Default: $upperlong\n"}
    else {chomp($upperlong)};
    print "Lower longitude[km] (default: -8000): ";
    my $lowerlong = <>;
    if ($lowerlong eq "\n") {$lowerlong = -8000;print "Default: $lowerlong\n"}
    else {chomp($lowerlong)};
    print "Upper latitude[km] (default: 10000): ";
    my $upperlat = <>;
    if ($upperlat eq "\n") {$upperlat = 10000;print "Default: $upperlat\n"}
    else {chomp($upperlat)};
    print "Lower latitude[km] (default: 0): ";
    my $lowerlat = <>;
    if ($lowerlat eq "\n") {$lowerlat = 0;print "Default: $lowerlat\n"}
    else {chomp($lowerlat)};
    # change from km to meter
    $upperlong = $upperlong * 1000;
    $lowerlong = $lowerlong * 1000;
    $upperlat = $upperlat * 1000;
    $lowerlat = $lowerlat * 1000;
    print "Checking...\n";
    
    # Initialize some variables
    my $deleteunit = 1;
    my $timeframe = 1;
    my $redstring = " ";
    my $counter = 0;
    my $groupcount = 0;
    my $unitcount = 0;
    my $unitcounter = 1;
    my $prevunitcount = 0;
    my $section = "[Group ";
    if ($layer eq "RND") {$section = "[RndGroup "};
    my $nextunit = $section.$unitcounter."]";
    my $prevunit = " ";
    my $stringlength = length($nextunit);
    my @delindx = ();
    my @delgroupindx = ();
    my @delunitindx = ();
    my $unitswitch = "n";
    my $ordswitch = "n";
    my $LongInside = 0;
    my $LatInside = 0;
    my $groupsfound = 0;
    my $unitsfound = 0;
    # Read file and check lines
    while((defined(my $i = <READF>))) {
        $redstring = substr($i,0,$stringlength);
        if ($redstring eq $nextunit) {
    	if (($deleteunit == 0) && ($timeframe == 1)){
    #	    print "$prevunit inside! \n \n";
    	    $counter++}
    	else {push(@delindx,$prevunitcount)};
    #	print "Found $nextunit \n";
    	$prevunitcount = $unitcounter;
    	$unitcounter++;
    	$deleteunit = 1;
    	$timeframe = 1;
    	$prevunit = $nextunit;
    	$nextunit = $section.$unitcounter."]";
    	$stringlength = length($nextunit);
        };
        $redstring = substr($i,0,14);
        if ($redstring eq "GameEntryDate=") {
    	$redstring = substr($i,14);
    	if ($redstring > $enddate) {$timeframe = 0};
        };
        $redstring = substr($i,0,13);
        if ($redstring eq "GameExitDate=") {
    	$redstring = substr($i,13);
    	if ($redstring < $startdate) {$timeframe = 0};
        };
        $redstring = substr($i,0,5);
        if ($redstring eq "Long=") { #print "Longitude found!\n";
    	$redstring = substr($i,5);
    	if (($redstring < $upperlong) && ($redstring > $lowerlong)) {
    	    $LongInside = 1;
    	};
        };
        $redstring = substr($i,0,4);
        if ($redstring eq "Lat=") { #print "Latitude found!\n";
    	$redstring = substr($i,4);
    	if (($redstring < $upperlat) && ($redstring > $lowerlat)) {
    	    $LatInside = 1;
    	};
            if (($LongInside == 1) && ($LatInside == 1)) {
    #	    print "Waypoint inside!\n";
    	    $deleteunit = 0;
    	};
    #        else {print "Waypoint outside!\n" };
            $LongInside = 0;
            $LatInside = 0;
        };
        $redstring = substr($i,0,8);
        if ($redstring eq "[Unit 1]") {
    	if (($deleteunit == 0) && ($timeframe == 1)){
    #	    print "$prevunit inside! \n";
    	    $counter++}
    	else {push(@delindx,$prevunitcount)};
    	$unitswitch = "y";
    	@delgroupindx = @delindx;
    	$groupcount = $counter;
    	$groupsfound = $unitcounter - 1;
    	$counter = 0;
    	@delindx = ();
    #	print "Found [Unit 1]\n";
    	$deleteunit = 1;
    	$timeframe = 1;
    	$prevunitcount = 1;
    	$unitcounter = 2;
    	$prevunit = "[Unit 1]";
    	$nextunit = "[Unit 2]";
    	$section = "[Unit ";
    	$stringlength = length($nextunit);
        };
        $redstring = substr($i,0,16);
        if ($redstring eq "[OrdnanceUnit 1]") {
    	if (($deleteunit == 0) && ($timeframe == 1)){
    #	    print "$prevunit inside! \n";
    	    $counter++}
    	else {push(@delindx,$prevunitcount)};
    	if ($unitswitch eq "n") {
    	    @delgroupindx = @delindx;
    	    @delunitindx = ();
    	    $groupcount = $counter;
    	    $groupsfound = $unitcounter - 1;
    	} else {@delunitindx = @delindx;
    		$unitcount = $counter;
    		$unitsfound = $unitcounter - 1;
    		$counter = 0};
    	@delindx = ();
    #	print "Found [OrdnanceUnit 1]\n";
    	$ordswitch = "y";
    	$deleteunit = 1;
    	$timeframe = 1;
    	$prevunitcount = 1;
    	$unitcounter = 2;
    	$prevunit = "[OrdnanceUnit 1]";
    	$nextunit = "[OrdnanceUnit 2]";
    	$section = "[OrdnanceUnit ";
    	$stringlength = length($nextunit);
        };
    };
    if (($deleteunit == 0) && ($timeframe == 1)){
    #    print "$prevunit inside! \n";
        $counter++}
    else {push(@delindx,$prevunitcount)};
    if ($ordswitch eq "n") {
        if ($unitswitch eq "n") {
    	@delgroupindx = @delindx;
    	@delindx = ();
    	$groupcount = $counter;
    	$groupsfound = $unitcounter - 1;
    	$counter = 0;
        } else {
    	@delunitindx = @delindx;
    	@delindx = ();
    	$unitcount = $counter;
    	$unitsfound = $unitcounter - 1;
    	$counter = 0;
        };
        $unitcounter = 1;
    };
    my $dummy = shift(@delgroupindx);
    my $dummy1 = 0;
    my $dummy2 = "PosTime_Campaign_".$layer.".mis";
    my @delordindx = @delindx;
    my $delNrgroup = @delgroupindx;
    my $delNrunit = @delunitindx;
    my $delNrordn = @delordindx;
    print "Final results: \n";
    print "**************\n";
    print "$groupsfound group(s) found! \n";
    print "$groupcount group(s) inside! \n";
    print "$unitsfound unit(s) found! \n";
    print "$unitcount unit(s) inside! \n";
    $unitcounter--;
    print "$unitcounter ordnance unit(s) found! \n";
    print "$counter ordnance unit(s) inside! \n \n";
    close(READF);
    
    print "Extract units (y/n)? ";
    my $extract = <>;
    chomp($extract);
    if ($extract eq "y"){
        print "Start extracting...\n";
        open(READF,"Campaign_$layer.mis")
    	or die "Error while opening the file: $!\n";
        open(WRITEF,"> $dummy2")
    	or die "Error while opening the file: $!\n";
        my $oldcount = 1;
        my $newcount = 0;
        my $write = 1;
        my $delcounter = 0;
        $section = "[Group ";
        if ($layer eq "RND") {$section = "[RndGroup "};
        $nextunit = $section.$oldcount."]";
        $prevunit = $nextunit;
        $stringlength = length($nextunit);
        @delindx = @delgroupindx;
        my $maxindx = $delNrgroup;
        my $prevstringlength = $stringlength;
        my $modstring = "";
        my $modstring2 = "";
        while((defined(my $i = <READF>))) {
    	$redstring = substr($i,0,8);
    	if ($redstring eq "[Unit 1]") {
    	    $oldcount = 1;
    	    $newcount = 0;
    	    $section = "[Unit ";
    	    $nextunit = "[Unit 1]";
    	    $stringlength = length($nextunit);
    	    @delindx = @delunitindx;
    	    $maxindx = $delNrunit;
    	    $delcounter = 0;
    	};
    	$redstring = substr($i,0,16);
    	if ($redstring eq "[OrdnanceUnit 1]") {
    	    $oldcount = 1;
    	    $newcount = 0;
    	    $section = "[OrdnanceUnit ";
    	    $nextunit = "[OrdnanceUnit 1]";
    	    $stringlength = length($nextunit);
    	    @delindx = @delordindx;
    	    $maxindx = $delNrordn;
    	    $delcounter = 0;
    	};
    	$redstring = substr($i,0,$stringlength);
    	if ($redstring eq $nextunit) {
    	    if ($delcounter < $maxindx) {
    		if ($oldcount == $delindx[$delcounter]) {
    		    $delcounter++;
    		    $write = 0;
    		    $newcount--;
    		} else {$write = 1};
    	    } else {$write = 1};
    	    $oldcount++;
    	    $newcount++;
    	    $prevstringlength = $stringlength;
    	    $prevunit = $nextunit;
    	    $nextunit = $section.$oldcount."]";
    	    $stringlength = length($nextunit);
    	};
    	$redstring = substr($i,0,14);
    	if ($redstring eq "[EditorParams]") {$write = 1};
    	if ($write == 1) {
    	    $dummy1 = $prevstringlength - 1;
    	    $redstring = substr($i,0,$dummy1);
    	    $dummy = substr($prevunit,0,$dummy1);
    	    if ($redstring eq $dummy) {
    		$modstring = substr($i,$dummy1);
    		$modstring2 = $section.$newcount.$modstring;
    		print WRITEF $modstring2}
    	    else {print WRITEF $i};
    	};
        };
        close(READF);
        close(WRITEF);
    };
  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,254
    Rep Power
    1810
    I don't use Windows, so I can not. But here's some info that might help.

    Running perl script on Windows
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    Originally Posted by keath
    I don't use Windows, so I can not. But here's some info that might help.

    Running perl script on Windows
    I don't think your link is about converting a perl script.

    Does Unix not use .exe files?

    Anyone else willing to do it?
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,254
    Rep Power
    1810
    Originally Posted by pditty8811
    Does Unix not use .exe files?
    No, Unix does not use .exe files.

    I don't think your link is about converting a perl script.
    In the first post you said:
    I have a perl script and I've tried many programs but for some reason nothing happens when I type the command.
    I thought it would be of great help to you to learn how to run a perl program. Sorry you are not interested in trying.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    54
    Rep Power
    2
    Originally Posted by keath
    No, Unix does not use .exe files.



    In the first post you said:


    I thought it would be of great help to you to learn how to run a perl program. Sorry you are not interested in trying.
    No need for you to apologize. Just be interested in reading a whole post.
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Interesting thing is that the first line of your program reads as:
    #!/usr/local/bin/perl -w

    Is perl installed on /usr/local/bin on your *nix system. Usually it is installed in /usr/bin on most flavors of *nix these days.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,930
    Rep Power
    1225
    Instead of asking someone to convert the script for you, maybe you should be asking for help in solving your real problem, which appears to be not knowing how to run perl scripts.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    830
    Rep Power
    496
    Well, I am not entirely sure of what the OP really wanted to know, but please, be patient with her or him. If the OP has only used so far purely compiled languages such as C, C++, Pascal or Ada, he or she might not know how to use interpreted or semi-compiled languages such as Perl, Python, TCL, Ruby or even Java. She or he might think that it is needed to go through a compile (and possibly link) phase.

    If the OP is a pure beginner, he or she might not yet know these things. Of course, there is plenty of documentation around there, but when you start, you don't necessarily fetch the right one to start with.

    To the OP: usually, the simplest way to run a Perl program is to type something like: "perl my_prog.pl arguments". There are some shortcuts, but they depend on your operating system.

    Please provide more information on what you are really looking for.

IMN logo majestic logo threadwatch logo seochat tools logo