Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Ways to store messages...

by Roger (Parson)
on Dec 12, 2003 at 06:01 UTC ( [id://314270]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Ways to store messages...

You could store the message definitions in an (external) xml configuration file.
use strict; use XML::Simple; my $msg = LoadMsgConfig(); print "$msg->{0}\n"; # look up by id print "$msg->{thanks}\n"; # look up by mnemonics sub LoadMsgConfig { my $xs = new XML::Simple(); my $xmlmsg = do { local $/; <DATA> }; my $tags = $xs->XMLin($xmlmsg); return undef if ! defined $tags->{msg}; my %msg; foreach (keys %{$tags->{msg}}) { $msg{$_} = $tags->{msg}{$_}{text}; $msg{$tags->{msg}{$_}{id}} = $msg{$_}; } # undef $xmlmsg, $tags, $xs; return \%msg; } __DATA__ <?xml version="1.0"?> <config> <msg id="0" name="wrong_input" text="Wrong input"/> <msg id="1" name="thanks" text="Thanks for signing up with us" +/> <msg id="2" name="go_away" text="Go away hacker"/> </config>
And the output -
Wrong input Thanks for signing up with us

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://314270]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.