Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Paths::Graph use

by RMGir (Prior)
on Aug 22, 2012 at 11:52 UTC ( #989013=note: print w/replies, xml ) Need Help??

in reply to Paths::Graph use

I don't think
my %graph = <FILE>
does what you think it does...

I think that will get you a "%graph" hash with the first line as a key, the 2nd line as a value, and so on so forth...

Try adding this right after you load %graph and see what it prints:

foreach my $k(keys %graph) { print "<<<<<\n$k ===>>>> $graph{$k}\n>>>>>\n" }


Replies are listed 'Best First'.
Re^2: Paths::Graph use
by zakishah (Novice) on Aug 22, 2012 at 17:44 UTC

    Thank you very much , but my purpose is not to print file here, my purpose is to read file and calculate the shortest distance between desitantion and origin, which my code is not calculating the problem is not with path calculation here but it is in reading file. Please suggest on this issue.

      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;


        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.


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989013]
[marinersk]: Corion This DBA wants to smack others who like putting whitespace in column names.
[marinersk]: s/smack/whap/;
[talexb]: Wow, what hilariously bad form.
[SuicideJunkie]: Just wait; someday soon, you'll be given a DB with unicode emojis in the column names.
[Corion]: marinersk: Well, I have done select statements like select sum(foo) as "Total Amount", ..., but to have a table like that makes me shudder

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-05-25 14:58 GMT
Find Nodes?
    Voting Booth?