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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
    0: #!/usr/bin/perl -W
    1: 
    2: # Copyright Jacob Filipp, 2003
    3: # This program is provided as is, you are free to use
    4: # it in any way as long as the copyright notice is
    5: # in the code
    6:  
    7: # Yes dear monks, Quick-And-Dirty-Operating-System (DOS)
    8: # is still used. Here is a tiny shell wrapper in Perl,
    9: # to implement all the wonderful features that DOS lacks
    10: # ,like command aliasing. Although this tiny script is
    11: # meagre compared to your mathematical-script prowess
    12: # it is very flexible and someone might actually like
    13: # to use it ( from sheer curiosity, of course ).
    14: 
    15: # The only fancy trick it has is the ability to launch
    16: # your browser when a URL is typed ( the first case in
    17: # the dispatch table. Interactive progs are run in a
    18: # separate window.
    19: 
    20: use Strict;     # just for you monks, I never use it
    21: 
    22: $SIG{ CHLD } = sub{ wait() };
    23: 
    24: $browser_path  = 'C:\Program Files\Internet Explorer\iexplore';
    25: $prompt   = sub{ 'Sh-wrap>' };	# can be a routine...
    26: @kids = ();			# forked processes
    27: 
    28: # dispatch table with regexes, used to execute commands
    29: # based on a shell command passed to it as an argument
    30: 
    31: %dispatch = (
    32: 
    33: '^(http://)?\S+\.(\w){3}.*$'        =>sub{
    34: 	my $kpid = fork();
    35: 	if( $kpid == 0 ){ exec("\"$browser_path\" $_[0]") and exit}
    36: 	else { push( @kids, $kpid ); sleep 1 }
    37: # sleep needed to make sure that child acts first
    38: 	},
    39: 
    40: '^cd\s'		=> sub
    41: 	{ $_[0] =~ s!^cd\s!!; chdir($_[0]) },
    42: 
    43: '^(exit|quit)$'	=> sub{ kill( 9, @kids); exit },
    44: 
    45: '^(ftp|telnet|edit|debug).*'	=> sub { `start $_[0]` }
    46: # interactive progs in new window
    47: # will barf when running ftpd, telnetter, editors, debuggame etc...
    48: );
    49: 
    50: WH: while(1)
    51: {
    52: 
    53: print $prompt->();
    54: my $line = <>;
    55: chomp $line;
    56: 
    57: foreach $regex ( keys %dispatch )
    58:  {
    59:    if( $line =~ m!$regex! )
    60:    { $dispatch{ $regex }->($line); next WH }
    61:    # permit only one match
    62:  }
    63: 
    64: print `$line`;
    65: 
    66: }

In reply to DOS Wrapper by bl0rf

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (7)
    As of 2015-07-06 09:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (70 votes), past polls