jv@mh.nl (Johan Vromans) (03/10/90)
I found the following perl program very helpful in exercizing Randal's
one-liners:
#!/usr/bin/perl
eval "exec perl -S $0 $*"
if $running_under_some_shell;
#
# StreamPerl - execute perl program from standard input
#
($version,$patchlevel) = $] =~ /(\d+.\d+).*\nPatch level: (\d+)/;
print "StreamPerl version $version, patchlevel $patchlevel\n";
$prog = "/usr/tmp/spl$$";
open (TMP, ">$prog") || die "Cannot create $prog, stopped";
print TMP while <STDIN>;
close TMP;
do $prog;
unlink ($prog);
In addition, the following program, based on the idea of a perl shell,
has proven very helpful on trying perl:
#!/usr/local/bin/perl
eval "exec perl -S $0 $*"
if $running_under_some_shell;
($version,$patchlevel) = $] =~ /(\d+.\d+).*\nPatch level: (\d+)/;
print "Interactive Perl version $version, patchlevel $patchlevel\n";
$Prompt = 'perl> ';
$Printing = "\n";
print $Prompt;
while (<stdin>) {
$Pres = eval $_ . ';';
print $Pres.$Printing if $Printing;
print $@;
print $Prompt;
}
Johan
--
Johan Vromans jv@mh.nl via internet backbones
Multihouse Automatisering bv uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands phone/fax: +31 1820 62944/62500
------------------------ "Arms are made for hugging" -------------------------
merlyn@iwarp.intel.com (Randal Schwartz) (03/10/90)
In article <JV.90Mar9110239@squirrel.mh.nl>, jv@mh (Johan Vromans) writes: | I found the following perl program very helpful in exercizing Randal's | one-liners: | | #!/usr/bin/perl | eval "exec perl -S $0 $*" | if $running_under_some_shell; | # | # StreamPerl - execute perl program from standard input | # | ($version,$patchlevel) = $] =~ /(\d+.\d+).*\nPatch level: (\d+)/; | print "StreamPerl version $version, patchlevel $patchlevel\n"; | | $prog = "/usr/tmp/spl$$"; | open (TMP, ">$prog") || die "Cannot create $prog, stopped"; | | print TMP while <STDIN>; | close TMP; | | do $prog; | | unlink ($prog); Izzer something wrong with: some_process_that_generates_perl | perl instead of your script above? That's how *I* execute fragments from news postings. (I use GNU Emacs to read news, so I just mark a fragment as a region, then feed the region as stdin to Perl. In fact, the sequence "mark-region", ESC-| perl <ret>, is very much locked into my fingers... especially while attacking a new .sig. :-) | In addition, the following program, based on the idea of a perl shell, | has proven very helpful on trying perl: | | #!/usr/local/bin/perl | eval "exec perl -S $0 $*" | if $running_under_some_shell; | | ($version,$patchlevel) = $] =~ /(\d+.\d+).*\nPatch level: (\d+)/; | print "Interactive Perl version $version, patchlevel $patchlevel\n"; | | $Prompt = 'perl> '; | $Printing = "\n"; | print $Prompt; | while (<stdin>) { | $Pres = eval $_ . ';'; | print $Pres.$Printing if $Printing; | print $@; | print $Prompt; | } This is very similar to 'perlsh' in the old distribution. I now do something a *whole* lot simpler: perl -de '0;' Yup. That's right. Debug a simple program given on the command line. Larry was even going to look at removing the need for the semicolon in a command line '-e' switch (ala 'eval'), so I could just type: perl -de 0 but that didn't make it into Patch 9 from who-knows-where. Maybe Patch 13 (the one that fixes the debugger...? :-). printf "%c"x 25,74,117,115,116,32,97,110,111,116,104,101,114,32,80,101,114,108,32,104,97,99,107,101,114,44; -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
tneff@bfmny0.UU.NET (Tom Neff) (03/10/90)
This is the version of the perl shell (psh) I hack with. It has a
couple of features I wanted:
* You can dump all the variables: X <enter>
* You can dump a scalar, quote delimited: p varname (no $ needed)
* Result of each op is displayed delimited: '(result=xyzzy)'
I'm sure there are a lot more things one could do. Biggest drawback
to psh is you can't load packages interactively; it blows up.
-----------------------------------------------------------------------
#!/usr/local/bin/perl
eval "exec perl -S -s $0 $*"
if $running_under_some_shell;
do 'dumpvar.pl' || die "No dumpvar.pl: $@\n";
$Prompt = 'psh: ';
$Printing = "\n";
print "(Hit X <enter> for a dump of variables)\n";
print $Prompt;
while(<stdin>) {
chop;
s/^p ([\w[\]{}']+)$/print q^\$$1=\"^,\$$1,q^\"\n^/;
s/^X$/\&dumpvar("main")/;
$Pres = eval $_ . ';';
print "(result=$Pres)$Printing" if $Printing;
print $@;
print $Prompt;
}
print "\npsh exit\n";