Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

perl -x to test while developing

by bsb (Priest)
on Apr 29, 2003 at 02:27 UTC ( #253886=snippet: print w/ replies, xml ) Need Help??

Description: Editing a large module and you want to run/compile just a sub-section. Add #!perl and '__END__' around the interesting bit and run it with perl -x

Vim ':make' integration is an exercise for the interested reader.

In MyFile.pm
half-baked pseudo-code
#!perl -wl -MData::Dumper

sub hohum {
    return bless {}, 'Something::Interesting';
}
print Dumper(hohum);

__END__
more bad code
Then at the command line:
$ perl -x -Mstrict MyFile.pm
or
$ perl -cx -Mstrict MyFile.pm
or even
$ perl -x -MO=Deparse MyFile.pm
PS. Riddle me this Batman:
$ perl -x
#!perl -MYAML -Mstrict
"-Mstrict" is not exported by the YAML module at - line 0
Can't continue after import errors at - line 0
BEGIN failed--compilation aborted.
Update: Changed -mstrict to -Mstrict per tye
Comment on perl -x to test while developing
Select or Download Code
Re: perl -x to test while developing (riddles)
by tye (Cardinal) on Apr 29, 2003 at 05:08 UTC

    Some more riddles:

    % perl -mstrict -le 'print $x**$y;' 1 % perl -l require strict; print $x**$y; <EOF> 1 % perl #!perl -MCarp -Mstrict Too late for "-MCarp" option %
    Perl's support for -M on the #! line is limited (to the point of not being supported at all in my version of Perl, v5.6.0). Your version appears to support it to some extent (was that small amount of support added or was it removed because it was buggy and too much work to do right?). That is why we have use.

    -mstrict does nothing useful, just like 'require strict;'.

    Oh, and nice trick. Thanks. (:

                    - tye
      -mstrict does nothing useful, just like 'require strict;'.
      Thanks, fixed.
      Although I maybe it's more like 'use strict ();'
      $ perl -mstrict=vars -le 'print $x**$y;' Global symbol "$x" requires explicit package...
      perlrun says "Any meaningful switches on that line will be applied" but "meaningful" seems to be strangely implemented. At least with 5.6.1.

      Here's another one:

      $ perl -x #!perl -wl -Mstrict -MB -MCGI Argument "MCGI" isn't numeric in subtraction (-). Argument "-MB" isn't numeric in subtraction (-).
        Although I maybe it's more like 'use strict ();'
        That's indeed what -m means, which, to be entirely precise, is like BEGIN { require strict }.

        Makeshifts last the longest.

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://253886]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2014-12-19 23:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (94 votes), past polls