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.
| [reply] [d/l] |
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.
| [reply] [d/l] [select] |
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 | [reply] [d/l] [select] |
|
|
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.)
| [reply] |
|
|
could you elaborate on "so that information that in one is maintained through mod_perl in the next has the Perl expanded out "? thanks
| [reply] |
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 | [reply] [d/l] [select] |
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
| [reply] |
Re: the -x command line parameter
by hbo (Monk) on Aug 09, 2004 at 06:38 UTC
|
| [reply] [d/l] |
Re: the -x command line parameter
by ambrus (Abbot) on Aug 09, 2004 at 08:49 UTC
|
| [reply] |
Re: the -x command line parameter
by davido (Cardinal) 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. ;)
| [reply] |
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
| [reply] |
Re: the -x command line parameter
by bsb (Priest) on Aug 10, 2004 at 00:12 UTC
|
| [reply] |
Re: the -x command line parameter
by Shenpen (Beadle) on Aug 09, 2004 at 19:03 UTC
|
| [reply] |