in reply to Re^2: Need script help
in thread Need script help

++ Thanks for your response.

I only started using PERL5OPT a few weeks ago because I was sick of having to add those pragmata whenever I wanted a quick one-liner.

The "perlrun: PERL5OPT" documentation starts:

"Command-line options (switches). Switches in this variable are treated as if they were on every Perl command line."

I took this to mean that (with my current PERL5OPT settings)

perl -E '...'

would be expanded to

perl -Mstrict -Mwarnings -Mautodie -E '...'

I ran quite a few tests and, when satisfied everything worked OK, modified my .bash_profile so that it would always be available.

It never occurred to me that this would affect scripts; however, following your comments, I've run additional script tests and it does appear that my shebang line

#!/usr/bin/env perl

is being altered to

#!/usr/bin/env perl -Mstrict -Mwarnings -Mautodie

As I always add strict and warnings to every script, and often add autodie, this is not a problem for me. So, while I thank you for alerting me to this, I will continue to use PERL5OPT as I'm currently doing unless I come across a good reason for not doing so.

"It makes your scripts non-portable."

Perhaps you could expand on this. I'm failing to see any portability issues.

— Ken

Replies are listed 'Best First'.
Re^4: Need script help
by haukex (Archbishop) on Sep 23, 2016 at 07:10 UTC

    Hi kcott,

    I assume what the AM is talking about is that scripts you write on your machine can omit warnings, strict and autodie, and if you copy that script to another machine - or even run it as another user - those pragmas will not be in effect there, altering the behavior of your scripts.

    Also, scripts you copy onto your machine are now suddenly running with autodie, which will also change their behavior.

    Regards,
    -- Hauke D

      G'day Hauke,

      ++ Thanks for the feedback. I've discontinued using PERL5OPT. See my response to AM tagged [PERL5OPT Resolution].

      — Ken

Re^4: Need script help
by Discipulus (Canon) on Sep 23, 2016 at 07:30 UTC
    if they were on every Perl command line means indeed every! oneliners, shebangs and even filetype associations on some unfortunate OS

    If you remember to put your desiderata in all your scripts too I see no problems.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.