Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Ways to store messages...

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


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
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: (5)
As of 2024-04-23 20:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found