Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

The Monastery Gates

( [id://131]=superdoc: print w/replies, xml ) Need Help??

New here?I want to ask a question of the Perl Monks. Where do I start?

Notices:

hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.

If you're new here, please read PerlMonks FAQ
and Create a new user!

Quests
poll ideas quest 2026
Starts at: Jan 01, 2026 at 00:00
Ends at: Dec 31, 2026 at 23:59
Current Status: Active
0 replies by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

Perl News
Videos of the German Perl Workshop 2026 are online
on Sep 06, 2026 at 10:09
0 replies by Corion

    If you want a taste of what to expect from a German Perl Workshop, the videos of this years presentations are now online on Youtube.

    Thanks again to all people presenting their projects and insights!

    See you in Hanover!

The London Perl & Raku Workshop 2026
on Aug 28, 2026 at 07:17
0 replies by choroba
    WHEN: Saturday 21 November 2026

    WHERE: The Café at Zoopla, The Cooperage, 5 Copper Row, London SE1 2LH

    Announcement at blogs.perl.org

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Cool Uses for Perl
Re-exec with custom perl
1 direct reply — Read more / Contribute
by hv
on Sep 08, 2026 at 09:41

    I have a bunch of mathematical projects, including lots of perl code. For these I usually use a custom-built perl optimized for speed and with a bunch of useful modules installed - locally that lives as a symlink under '/opt/maths/perl'.

    That then leaves me with a tension: for my own convenience I want the shebang line on the perl programs to point to this custom perl, but that then makes like difficult for others when I make the code available on github, particularly since they are designed to be run in-repository without an installation step.

    Today I finally decided to do something about that. I want the designated scripts (and only those) to use the custom perl when I run them, but to be usable by others using standard setups, and to be fairly robust against user error. And I want any preamble to be as terse as possible. After a bunch of back and forth with both Claude and Gemini, I ignored all their suggestions and went with this instead.

    In a script:

    #!/usr/bin/env perl BEGIN { do "./lib/reexec" for grep $_, $ENV{MATHPERL} }

    And in 'lib/reexec':

    BEGIN { if ($ENV{REEXEC_LOOP}) { delete $ENV{REEXEC_LOOP}; } elsif ($^O =~ /MSWin32/) { warn "Ignoring re-exec under Windows"; } else { local $ENV{REEXEC_LOOP} = 1; exec($_, $0, @ARGV); die "Could not exec $_"; } }

    I don't know how easy it would be to extend this to work safely under Windows: probably calling system() and then unmunging the exit value would work better then messing with ShellQuote.

    Suggestions for improvement welcomed. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2026-09-09 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.