Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Perl bytecode on unix

by fpi (Monk)
on Mar 08, 2001 at 12:48 UTC ( #62936=perlquestion: print w/replies, xml ) Need Help??
fpi has asked for the wisdom of the Perl Monks concerning the following question:

1) How do I execute a perl file that I already converted to bytecode (perl -MO=Bytecode Specifically, how do I use the byteload_fh () function mentioned in the docs? Even if you are not sure, I would appreciate a guess as to how to experiment, since I am not good with filehandles.

2)I found the module, but I'm not sure if I'm using it correctly, and if I am, I can't get it to work all the time (even with a simple helloworld script, sometimes it works, sometimes not, beats me....). Basically I just open up the file containing the bytecode, add the following to the top of the file:
#!/usr/bin/perl use ByteLoader 0.03;
after which the bytecode follows. I would rather use byteload_fh() if I only knew how.

3) will converting to bytecode include the perl modules that I have "used" in my script? or does that only happen with a full C (perlcc) compile?

Replies are listed 'Best First'.
Re: Perl bytecode on unix
by LD2 (Curate) on Mar 16, 2001 at 16:23 UTC
    fpi, to answer your first question.. you can use:
    • 1. ByteLoader module
    • 2. byteload_fh(FILEHANDLE) that is included with the B module
    Which it seems like you're familiar with both of these ways...

    From the looks of the second question, you're using ByteLoader correctly. Remember that it's still in experimental phase.. which would explain why it's a bit unstable. I believe there is an updated version coming out.

    I believe you need to do a full compile(perlcc) to include other scripts that you used in your main script. If you run perlcc with the -b flag, it will generate bytecode instead of C code.. i.e. perlcc -b

    Here are a few good links:
      LD2, thanks for the post. After reading through the links you posted and then further testing, here's the first little interesting thing I found:

      perl -MO=Bytecode,-omyfile.bc produces the bytecode file, as before

      perlcc -b -o myfile.bc produces the bytecode, and automatically sticks in the perl header and use Byteloader 0.03; statement. The only problem was the perl header pointed to /perl instead of /usr/bin/perl, so I had to go in and edit anyway. But at least now I know that I was using the ByteLoader module correctly, since that was the way that perlcc sets it up.

      Thanks for the filehandle links too. I'm trying to experiment with byteloader_fh() again, but I'm getting "Undefined subroutine B::byteload_fh" errors. I reloaded the B modules....I just found out that you can't reload the B modules without reloading all of perl....

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://62936]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-05-23 09:34 GMT
Find Nodes?
    Voting Booth?