On Fri, Sep 13, 2013 at 01:31:47PM +0100, David Precious wrote:
> On Fri, 13 Sep 2013 19:10:58 +0800 (SGT)
> *Shaji Kalidasan* <shajiin...@yahoo.com> wrote:
> > I am saving the data structure to a file and retrieving it back
> > again, but, when I 'use strict' it is giving the following error
> > message
> > 
> > Global symbol "%game" requires explicit package name
> 
> Others have pointed out that the problem will be solved by adding a "my
> %game" before you eval the contents of the file.
> 
> However, I personally would suggest serialising the data to JSON and
> storing that in the file, rather than using Data::Dumper - that way
> you've got your data in a more standard format in case you want to work
> with it with other tools, and also you're not eval'ing code, so if
> someone had decided to edit that file and add, say, system('rm -rf /')
> in it, you won't suddenly execute things you didn't expect.
> 
> It can be as simple as saying "use JSON" to load JSON.pm, then using
> JSON::to_json(\%game) to generate JSON to write to the file, then
> saying e.g. my $game = JSON::from_json($json) (where $json is the JSON
> you just read in from the file).
> 
> Alternatively, you could even look at DBM::Deep, which would abstract
> away the saving/loading for you (although you'd lose the bonus of
> having stored the data in a standard widely-supported format).
> 
A shame we can't rate answers on beginners but that is an excellent answer and
really informative. 

Thanks David.
<snip>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to