Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

making 'use strict' default conflicts with CORE modules/scripts

by LanX (Cardinal)
on Dec 12, 2014 at 19:21 UTC ( #1110202=perlquestion: print w/replies, xml ) Need Help??

LanX has asked for the wisdom of the Perl Monks concerning the following question:

A perlmongers friend of mine asked me how to avoid boilerplate when typing snippets interactively on the console...

(... also bitching around that Modern::Perl isn't CORE and that there are no packages to install it, neither for Debian nor Win...)

So I suggested to just configure PERL5OPT export PERL5OPT='-Mstrict' and so on for his other default stuff.

Problem now is that perldoc (!!!) fails in that environment ... and I suppose there are more core-modules with similar problems (jeeeez ... o.O )

lanx@lanx-1005HA:~$ export PERL5OPT="-Mstrict" lanx@lanx-1005HA:~$ perldoc perldoc Global symbol "$running_under_some_shell" requires explicit package na +me at /usr/bin/pod2man line 6. BEGIN not safe after errors--compilation aborted at /usr/bin/pod2man l +ine 18. Got a 0-length file from /usr/share/perl/5.14/pod/perldoc.pod via Pod: +:Perldoc::ToMan!?

ok this could be solved with an extension to Modern::Perl checking for an exception list of old "unstrict" modules in the caller and including this extended modern module into PERL5OPT.

After all this is only meant for the console....

Anyway I started to investigate /usr/bin/pod2man to isolate the problem and found the following code:

#!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; # not running under some shell eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; # pod2man -- Convert POD data to formatted *roff input. # # Copyright 1999, 2000, 2001, 2004, 2006, 2008, 2010 # Russ Allbery <rra@stanford.edu> # # This program is free software; you may redistribute it and/or modify + it # under the same terms as Perl itself. require 5.004; use Getopt::Long qw(GetOptions); use Pod::Man (); use Pod::Usage qw(pod2usage); use strict; # ...

so all of this comes from dual code to allow the script to be run under perl and *sh equally.

I'm puzzled, any good idea how to "strictify" this?

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

update

not sure how pod2man is called but if $running_under_some_shell is a perl variable, it should be sufficient to fully qualify it like with $main::running_under_some_shell but I suppose it's rather a shell var...

Replies are listed 'Best First'.
Re: making 'use strict' default conflicts with CORE modules/scripts
by atcroft (Abbot) on Dec 12, 2014 at 19:55 UTC

    I tested using the following test case: PERL5OPT="-Mstrict -Mwarnings" perldoc -f time

    When you first mentioned this in the CB, I had access to perl 5.10.x (RHEL/CentOS/Fedora) and 5.14.x (Cywgin on MSWin), both with as-packaged perl versions. A short time later, I was able to test against a Fedora system with perlbrew, and got the following results:

    Hope that helps.

    Update: 2014-12-12
    Note: The initial results mentioned were consistent with the results presented in the table.

      mine is This is perl 5, version 14, subversion 2 (v5.14.2)

      I suppose pod2man was changed between the versions.

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re: making 'use strict' default conflicts with CORE modules/scripts
by ysth (Canon) on Dec 12, 2014 at 20:06 UTC

    No, it is not a shell variable. In fact, a shell will do the eval without even having seen the if. It's just intended to be self-documentation but work the same as "if 0". (So the code is completely unneeded, since the eval...if 0 will have already done the perlification work if necessary.)

    --
    A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |
      looks for me like a workaround for shells which do handle if 0 . (though unless 1 would be fine too)

      Anyway like atcroft pointed out there seem to be diffrerent versions of pod2man circulating ...

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re: making 'use strict' default conflicts with CORE modules/scripts
by fishmonger (Chaplain) on Dec 12, 2014 at 20:09 UTC

    How do you and your friend typically execute your scripts?

    If you execute it like this perl foo.pl, you could enable strict like this perl -Mstrict foo.pl or perl -Mv5.11 foo.pl

    That will reduces the amount of boiler plate in the script at the cost of a bit of "boiler plate" when executing

      > How do you and your friend typically execute your scripts?

      that's his use case:

      lanx@lanx-1005HA:~$ export PERL5OPT="-Mstrict -Mwarnings -MData::Dump +-Mfeature=say" lanx@lanx-1005HA:~$ perl say "huhu"; dd [1,2,3] __END__ huhu [1, 2, 3]

      of course he could alias perl to restrict the effect to the interactive shell only, but I'd like to know if PERL5OPT is usuable after all.

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1110202]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2020-10-21 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (212 votes). Check out past polls.

    Notices?