Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: Parsing conditional expressions

by Lorand (Beadle)
on Mar 23, 2004 at 14:15 UTC ( [id://339005]=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing conditional expressions
in thread Parsing conditional expressions

I need this to match some packets stored in XML (actually PDML) format. I use XML::Parser to parse the document, and when I detect an end tag </packet> I want to see if that packet meets some conditions or not.

I need this to determine some phases of the packet flow, so I will have about 6 packet types that have to be matched, and that has to be extensible and easily modifyable, so I don't want to hardcode it. Security is not a concern, it's for a personal project.

Thanks for the answers so far.

  • Comment on Re: Re: Parsing conditional expressions

Replies are listed 'Best First'.
Re: Re: Re: Parsing conditional expressions
by dragonchild (Archbishop) on Mar 23, 2004 at 14:34 UTC
    Create a class called Packet and subclasses called Packet::TypeA, Packet::TypeB, etc. Then, using a factory, create the appropriate subclass. Have each subclass know how to validate itself. No need for eval.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      OK, I didn't think of this, it seems to be the best solution, however I don't know what a factory is, and couldn't find anything that would make that clear... Could you point me to some relevant documentation, maybe a place with examples?
        A factory is a class or object that creates objects. It's a design pattern. Try googling for "object factory design pattern perl". The first several links look good.

        The basic concept is that you ask the factory for an object given a set of parameters and it returns back an object of the appropriate class(es), if possible.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-18 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found