Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: First Perl mention, was Re: First mention of Star Wars in Google

by eduardo (Curate)
on Dec 13, 2001 at 19:50 UTC ( #131638=note: print w/replies, xml ) Need Help??

in reply to First Perl mention, was Re: First mention of Star Wars in Google
in thread (Not Perl) First mention of Star Wars in Google

So I got to looking at the first perl node that you mention... what an incredibly interesting piece of history! Larry pretty much had the right idea all along :) I however especially like his sample code:
#!/bin/perl $SIG{'QUIT'} = 'quit'; # install signal handler for SIGQUIT while ($ARGV[0] =~ /^-/) { # parse switches $ARGV[0] =~ /^-h/ && ($showhost++,$silent++,shift,next); $ARGV[0] =~ /^-s/ && ($silent++,shift,next); $ARGV[0] =~ /^-d/ && ($dodist++,shift,next); $ARGV[0] =~ /^-n/ && ($n=' -n',shift,next); $ARGV[0] =~ /^-l/ && ($l=' -l ' . $ARGV[1],shift,shift,next); last; } $systype = shift; # get name representing set of hosts while ($ARGV[0] =~ /^-/) { # we allow switches afterwards too $ARGV[0] =~ /^-h/ && ($showhost++,$silent++,shift,next); $ARGV[0] =~ /^-s/ && ($silent++,shift,next); $ARGV[0] =~ /^-d/ && ($dodist++,shift,next); $ARGV[0] =~ /^-n/ && ($n=' -n',shift,next); $ARGV[0] =~ /^-l/ && ($l=' -l ' . $ARGV[1],shift,shift,next); last; } if ($dodist) { # distribute input over all rshes? `cat >/tmp/gsh$$`; # get input into a handy place $dist = " </tmp/gsh$$"; # each rsh takes input from there } $cmd = join(' ',@ARGV); # remaining args constitute the com +mand $cmd =~ s/'/'"'"'/g; # quote any embedded single quotes open(ghosts, '/etc/ghosts') || die 'No /etc/ghosts file'; # /etc/ghosts drives the rest $one_of_these = ":$systype:"; # prepare to expand "macros" if ($systype =~ s/\+/[+]/g) { # we hope to end up with list of $one_of_these =~ s/\+/:/g; # colon separated attributes } line: while (<ghosts>) { # for each line of ghosts s/[ \t]*\n//; # trim leading whitespace if (!$_ || /^#/) { # skip blank line or comment next line; } if (/^([a-zA-Z_0-9]+)=(.+)/) { # a macro line? $name = $1; $repl = $2; $repl =~ s/\+/:/g; $one_of_these =~ s/:$name:/:$repl:/; # do expansion in "wanted" + list next line; } # we have a normal line @attr = split; # a list of attributes to match against # which we put into an array $host = $attr[0]; # the first attribute is the host nam +e if ($showhost) { $showhost = "$host:\t"; } attr: while ($attr = pop(attr)) { # iterate over gh arr +ay if (index($one_of_these,":$attr:") >=0) { # is host wanted? unless ($silent) { print "rsh $host$l$n '$cmd'\n"; } $SIG{'INT'} = 'DEFAULT'; if (open(pipe,"rsh $host$l$n '$cmd'$dist |")) { # start rsh $SIG{'INT'} = 'cont'; while (<pipe>) { print $showhost,$_; } # show results close(pipe); } else { $SIG{'INT'} = 'cont'; print "(Can't execute rsh.)\n"; } last attr; # don't select host twice } } } unlink "/tmp/gsh$$" if $dodist; # here are a couple of subroutines that serve as signal handlers sub cont { print "\rContinuing...\n"; } sub quit { $| = 1; print "\r"; $SIG{'INT'} = ''; kill 2, $$; }
:) I think it'd be fun to translate that to perl 5 (or 6 even) and use all of the new tools... funny thing is, that code would be chastized on perlmonks like crazy... no strict, no -w, handrolled commandline parsing! tsk tsk tsk. (I know that Perl back then didn't have these things, my sarcasm flag is set to 1 :) Also, a very interesting little historical sidenote:
I wasn't going to add a "goto" except that the sed-to-perl translator needed one.
:) how fun is that! Also of note: On top of which, C didn't have the picture-style report formats I wanted. And I didn't want to do a make every time I tweaked the program. I take it he is talking about perl formats... a feature that has now been voted out of the core and into a module (if memory serves me right...) So, I guess that says a few things about how perl has moved from a systems management / formatting language to a much more general beast. I guess he succeeded when he said he wanted to make a language that is: intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal).
  • Comment on Re: First Perl mention, was Re: First mention of Star Wars in Google
  • Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-02-27 17:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found