Home: Perl Programming Help: Advanced:
do, but as if with -x ?

New User

Jul 9, 2013, 11:59 AM

Views: 14590
do, but as if with -x ?

Hello all

Expecting the answer no, but is there any built-in way to 'do' a Perl source file in the way that the -x switch would (discard leading garbage etc etc)?



Jul 9, 2013, 3:01 PM

Views: 14585
Re: [dugeen] do, but as if with -x ?

Let me make sure that I understand you correctly. You have two files. The first is a normal perl program. The second has perl code embedded in something else. You want the first program to execute the perl code in the second. You can execute that code from the command line by using perl -x secondfile.

Good question. I agree that there probably is not an easy way to do it. You could read the second file into a string and execute the string. Use the flip/flop operator (..) to store only the lines from the #! to the __END__.
Good Luck,

New User

Jul 10, 2013, 2:20 PM

Views: 14575
Re: [BillKSmith] do, but as if with -x ?

Yep, you've understood me perfectly.

It's as I thought, then - I have to parse the Perl code out from the second file myself, and 'eval' or 'do' it when I've got it.