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

the -x command line parameter

by Shenpen (Beadle)
on Aug 08, 2004 at 19:55 UTC ( #381091=perlquestion: print w/ replies, xml ) Need Help??
Shenpen has asked for the wisdom of the Perl Monks concerning the following question:

Fratres Perlis saluto!

I've recently read the perlrun manpage, and wonder what the -x parameter is for. What purpose had Larry in mind when creating this functionality? The manpage mentions e-mail headers as an example, hmmmm... maybe this feature is to send programs to your computer in e-mail? Could someone suggest some useful, practical or fun uses of the -x parameter, especially for e-mails?

cum gratiae maximae,

Shenpen

Comment on the -x command line parameter
Re: the -x command line parameter
by Joost (Canon) on Aug 08, 2004 at 20:02 UTC
    Well... say I get an email or usenet message with a perl program in the body:
    From: my@email.com To: your@email.com Subject: perl program Hello here is my program hope you like it, Joost. #!/usr/bin/perl -w use strict; print "Just another perl hacker\n";
    I can save it as "message.txt". And then
    > perl -x message.txt Just another perl hacker
    It's just another example of perl making easy things easy.

    J.

Re: the -x command line parameter
by BUU (Prior) on Aug 08, 2004 at 20:08 UTC
    Another useful and actual real world example is <Perl></Perl> sections in the Apache httpd.conf file. You can simply do:
    randomApacheVar = 1 var2=3 <Perl> #!perl my $perl = 'code'; some('more','code'); #etc __END__ </Perl>
    And easily check if it compiles, or even what it does by doing perl -x httpd.conf
      You can do even better than that. I've seen the above technique used to create synchronized httpd.conf files, so that information that in one is maintained through mod_perl in the next has the Perl expanded out so that it can be used with a non-mod_perl Apache server. (This for a reverse proxy config, the non-mod_perl server handles all of the static requests and forwards what it needs to to the mod_perl servers.)
        could you elaborate on "so that information that in one is maintained through mod_perl in the next has the Perl expanded out "? thanks
Re: the -x command line parameter
by Aristotle (Chancellor) on Aug 08, 2004 at 20:09 UTC

    I've used -x to bundle shell scripts with Perl code, as in

    #!/bin/sh complex-pipeline-with | perl -x "$0" | while read LINE ; do something-with-output done exit 0 ################### #!/usr/bin/perl -pl use strict; use warnings; # some relatively complex string mangling here

    Makeshifts last the longest.

Re: the -x command line parameter
by GreyGlass (Sexton) on Aug 08, 2004 at 20:57 UTC
    I use perl -x to run bits of setup on various test systems on a trusted net:

    # telnet <my-development-box> <some-port> | perl -x

    On the development box I simply have an inetd server at <some-port>, that cat(1)'s the relevant setup script.

    perl -x eats the telnet garbage from the front of the output.

    ---GreyGlass

Re: the -x command line parameter
by davido (Archbishop) on Aug 09, 2004 at 03:37 UTC

    In a language so well known for its rich text processing capabilities, and given that Perl scripts are textual, I would be more surprised to find this sort of feature missing, than to find of its existance.

    On a commical side-note, such an embeded Perl script would come in handy for one of those Mission Impossible "This message will self-destruct in sixty seconds." dispatches. ;)


    Dave

Re: the -x command line parameter
by hbo (Monk) on Aug 09, 2004 at 04:46 UTC
    Larry Wall first came to the attention of the wider computing world as the author of patch and rn. The latter, the niftiest usenet news reader of its day, is rarely seen now, but patch is everywhere. In the days when programs were passed around in shar (shell archive) files via usenet, patches (diffs) were generally sent in usenet email, too. Larry made patch ignore anything that didn't look like a diff so you could pipe the message (out of rn, naturally) to patch and have it Do The Right Thing.

    Though I can't prove it, (without working harder than I care to on a Sunday night) I'm pretty sure the -x switch in Perl harks back to this use of patch on usenet. Not that it isn't still useful, as others have noted.

    "Even if you are on the right track, you'll get run over if you just sit there." - Will Rogers

Re: the -x command line parameter
by hbo (Monk) on Aug 09, 2004 at 06:38 UTC
    An example of how Larry (or someone playing him on TV) uses perl -x:

    From http://search.cpan.org/src/JHI/perl-5.8.1/patchlevel.h:

    So we have perl -x used in a context similar to how patch was used on usenet, and associated with patching, too.

    "Even if you are on the right track, you'll get run over if you just sit there." - Will Rogers

Re: the -x command line parameter
by ambrus (Abbot) on Aug 09, 2004 at 08:49 UTC
Re: the -x command line parameter
by mce (Curate) on Aug 09, 2004 at 12:26 UTC
    Strange that nobody mentioned pl2bat yet.
    I 'll do it.

    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    BMC, Belgium
Re: the -x command line parameter
by Shenpen (Beadle) on Aug 09, 2004 at 19:03 UTC
    Thank you all very much.
Re: the -x command line parameter
by bsb (Priest) on Aug 10, 2004 at 00:12 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-10-01 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (41 votes), past polls