Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: Running perlscript on windows sytems that don't have Perl installed

by ozgurp (Beadle)
on Jun 06, 2003 at 01:03 UTC ( #263570=note: print w/replies, xml ) Need Help??


in reply to Re: Running perlscript on windows sytems that don't have Perl installed
in thread Running perlscript on windows sytems that don't have Perl installed

I am already using PerlApp. I have a code that extracts certain type of elements from a text file. These elements have names like QUAD, CBAR, CROD. I have a while loop that reads the files line by line and extracts required info.
while(<FH>){ if($_ =~ C B A R){ do something } if($_ =~ Q U A D){ do something } if($_ =~ C R O D){ do something } if($_ =~ C B E A M){ do something } if($_ =~ C E L A S 1){ do something } ... }
Now the problem is I have 38 different element types and 20 files with 100 MB info in total abot 2 GB. If I have a fixed code then it takes too long to read these files. My solution was to quickly re constract my code based on user selection and run that code instead of the fixed long one. So the new script will only be looking for selected elements in the while loop. I will open a new file newcode.pl write reconstracted algorithm into that code and close it. and then run it. This will prevent the code looking for unwanted elements and significantly reduce the time spent.
while(<FH>){ if($_ =~ C B A R){ # selected element do something } if($_ =~ Q U A D){ # selected element do something } }
I will have an .exe file doing this (PerlApp) but I can not compile the reconstructed code with PerlApp. Because the users of this program will not have PerlApp on their machines, they will not have perl on their machines either. So how can I run this reconstructed script.

Replies are listed 'Best First'.
Re: Re: Re: Running perlscript on windows sytems that don't have Perl installed
by BUU (Prior) on Jun 06, 2003 at 01:22 UTC
    Instead of rewriting the perl script and so forth, why not just just have a hash containing all the regexes and simply interpolate which ever one you want, i.e.
    my $regex="C B A R"; #however you choose to define it while(<FH>) { if(/$regex/o) # do something; }
Re: Re: Re: Running perlscript on windows sytems that don't have Perl installed
by meredith (Friar) on Jun 06, 2003 at 03:03 UTC
    PerlApp does exactly what you want, but behind the scenes. you should look into --add to include extra modules in the exe. It extracts them in $ENV{TEMP}/PDK and sets the lib to there. (yeah this skips some detail) I really would like to see the technique you're using on this.
    One thing to note is that PerlApp and Perl2Exe dont compile your app per se. they simply put every file needed in a self-extracting wrapper. You can also embed files in the exe and use a module (sorry don't know exactly.. PerlApp.pm maybe?) to pull the files back out at runtime.

    Hope I helped!

    mhoward - at - hattmoward.org
Re: Re: Re: Running perlscript on windows sytems that don't have Perl installed
by CountZero (Bishop) on Jun 06, 2003 at 06:24 UTC

    Sure you can have your PerlApp or Perl2Exe program "compile" another Perl-program. Just write your "new" Perl-program to a file or keep it in a scalar and then do or eval it.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Re: Re: Running perlscript on windows sytems that don't have Perl installed
by thor (Priest) on Jun 06, 2003 at 04:57 UTC
    Stylistic issues aside (you don't need to name $_, you can just do if(m/C B A R/), but I digress), you could probably speed up your code if your test cases are mutually exclusive. That is to say that if 'CBAR' and 'QUAD' will never appear on the same line, you can use elsif instead of if. The elsif will short circuit, thereby eliminating a ton of pattern matches. For more speed, put the more common cases towards the top of the chain of if..elsif..elseif so that it short circuits as early as possible.

    HTH,
    thor

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://263570]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-05-24 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?