Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Problem with Tie::RegexpHash

by sch (Pilgrim)
on Oct 10, 2002 at 18:43 UTC ( #204275=note: print w/ replies, xml ) Need Help??


in reply to Re: Problem with Tie::RegexpHash
in thread Problem with Tie::RegexpHash

decided to add this as a seperate node

This is the starting point I've got so far:

#!/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"; }

which when called as above returns:

called cmd with 12 arg2

and if the line:
my $txt = "cmd 12 arg2";
is changed to
my $txt = "quit";
returns:

called quit


Comment on Re: Re: Problem with Tie::RegexpHash
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-07-11 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (220 votes), past polls