develooper Front page | perl.perl5.porters | Postings from July 2020

Re: Perl 7 - updates

Thread Previous | Thread Next
From:
Todd Rinaldo
Date:
July 4, 2020 00:36
Subject:
Re: Perl 7 - updates
Message ID:
D029E63C-0EA7-4A3E-8E75-8A2E95CB302E@cpanel.net


> On Jul 3, 2020, at 7:28 PM, Kent Fredric <kentfredric@gmail.com> wrote:
> 
> On Sat, 4 Jul 2020 at 12:10, Todd Rinaldo <toddr@cpanel.net> wrote:
> 
>> I'm working on a module right now that will walk a file tree and auto-inject 'use v5;' at the top of any Perl code (as the first line of the file after any #!) that does not have use vX. It then also auto-updates the XS code with its faulty version checks. I think this will solve 99% of CPAN and the 1% outlier (I don't know of any outliers at the moment) can be fixed by hand if it needs it.
> 
> Something to consider:
> 
> I recall seeing some perl scripts which had a nice little blob of code
> at the top, which did nothing on perl, but due to *also* being valid
> bash, prevented bash getting carried away trying to execute the rest
> of the code as bash script.
> 
> If there's a way to do that nicely, that'd be cool. ( Though I
> speculate this will very much fall into a hard basket, as `use vX`
> probably isn't valid bash )

This used to live at the top of some cPanel perl code until we found a better solution. It allowed the code to fall back to system perl in the event cPanel Perl was broken in some way.

#!/bin/sh
eval 'if [ -x /usr/local/cpanel/3rdparty/bin/perl ]; then exec /usr/local/cpanel/3rdparty/bin/perl -x -- $0 ${1+"$@"}; else exec /usr/bin/perl -x $0 ${1+"$@"}; fi;'
  if 0;

#!/usr/bin/perl


As far as I understand, the Perl parser doesn't start parsing the code until it sees #!/usr/bin/perl in which case you just put use v7 after that line.

Todd

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About