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

Re^3: Paths::Graph use

by RMGir (Prior)
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 '10.0.0.128' => { '10.0.0.129'=>3, '10.0.0.129'=>4, '10.0.0.130'=>3, '10.0.0.131'=>2, '10.0.0.132'=>1, '10.0.0.133'=>1, '10.0.0.134'=>2, '10.0.0.135'=>4, '10.0.0.136'=>1, '10.0.0.137'=>4, '10.0.0.138'=>3 }, '10.0.0.129' => { '10.0.0.128'=>3, '10.0.0.130'=>1, '10.0.0.131'=>2, '10.0.0.132'=>1, '10.0.0.133'=>2, '10.0.0.134'=>1, '10.0.0.135'=>2, '10.0.0.136'=>3, # the > was missing on this line... '10.0.0.137'=>3, '10.0.0.138'=>4 }, );
Now your reading code can simply be:
my $x=join "",<FILE>; my %graph = eval $x;

Mike


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:

    my $x=join "",<FILE>; my %graph = eval $x;

    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.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2014-10-22 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (113 votes), past polls