
Problems? Is your data what you think it is?

Re^3: Paths::Graph use

by RMGir (Parson)
on Aug 23, 2012 at 12:12 UTC ( #989300=note: print w/ replies, xml ) Need Help??

in reply to Re^2: Paths::Graph use
in thread Paths::Graph use

Why not structure your data as correct perl, then just read it in and eval it?

# data file ( # Quoting the dotted quads since => will not quote # those correctly '' => { ''=>3, ''=>4, ''=>3, ''=>2, ''=>1, ''=>1, ''=>2, ''=>4, ''=>1, ''=>4, ''=>3 }, '' => { ''=>3, ''=>1, ''=>2, ''=>1, ''=>2, ''=>1, ''=>2, ''=>3, # the > was missing on this line... ''=>3, ''=>4 }, );
Now your reading code can simply be:
my $x=join "",<FILE>; my %graph = eval $x;


Comment on Re^3: Paths::Graph use
Select or Download Code
Re^4: Paths::Graph use
by afoken (Parson) on Aug 24, 2012 at 04:20 UTC

    Now your reading code can simply be:


    Please don't use string-eval to read data files. CPAN has several data file readers that don't crash your program or erase your harddisk if the data file contains unexpected data. Think about JSON, YAML, or, if you have no better idea, XML. None of those formats is read as executable code.

    And if you really can't avoid string-eval, at least use Safe in a "deny-almost-everything" configuration.



Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-03-13 23:16 GMT
Find Nodes?
    Voting Booth?

    Have you used a cryptocurrency?

    Results (293 votes), past polls