note
sch
<P><i>decided to add this as a seperate node</i><P>
<P>This is the starting point I've got so far:
<CODE>#!/usr/bin/perl -w
use strict;
use diagnostics;
my %cmds;
my $rgx;
my $sub;
$cmds{qr/^\s*quit/} = \&quit;
$cmds{qr/^\s*cmd .*/} = \&cmd;
my $txt = "cmd 12 arg2";
foreach $rgx (keys(%cmds)) {
if ( $txt =~ /$rgx/i ) {
$sub = $cmds{$rgx};
&$sub($txt);
}
}
exit;
sub quit {
print "called quit\n";
}
sub cmd {
my ($cmd, @argx) = split /\s+/, $_[0];
print "called ".$cmd." with ".$argx[0]." ".$argx[1]."\n";
}
</CODE>
<br>which when called as above returns:<br><br>
<i>called cmd with 12 arg2</i><br><br>
and if the line: <CODE>
my $txt = "cmd 12 arg2"; </CODE>is changed to<CODE>
my $txt = "quit";</CODE>returns:<br><br>
<i>called quit</i></P>
204227
204250