Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Re: Re: Problem with Tie::RegexpHash

by Mr. Muskrat (Canon)
on Oct 10, 2002 at 17:32 UTC ( [id://204247]=note: print w/replies, xml ) Need Help??

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

After having read the docs for Tie::RegexpHash, I still haven't found a solution. I'd say that your best bet would be to contact the author.
  • Comment on Re: Re: Re: Problem with Tie::RegexpHash

Replies are listed 'Best First'.
Re: Problem with Tie::RegexpHash
by sch (Pilgrim) on Oct 10, 2002 at 17:36 UTC

    Yup, having to do that - was trying to get something working quickly and hoped someone else had come across a solution

    What I'm trying to do is a simple parser for some commands and I was thinking of using a hash with the keys being regexp's that would match commands and the value's being references to functions - if anyone knows of another way of doing it I'm always willing to change direction mid-flow :)

      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";

      called quit

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-07-21 04:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.