in reply to Perl code for finding shortest path not working on large files
Hello zing,
A little debugging reveals that the difference in behaviour has nothing to do with the length of the two input files, and everything to do with the fact that in the file which works, each line has a comma immediately before the newline, whereas in the file which fails (p17226.csv), the comma is missing. When this terminal comma is omitted, split leaves the newline in the final field. So the call to rank() accesses, e.g., $rank{"E\n"}, which is different to $rank{"E"}, and since the former key does not exist in the hash, the comparison generates a warning and fails to work as desired.
Like QM, I’m largely in the dark as to what this code is doing and how it is supposed to work. However, by changing this:
ins split /,\s*/ for <DATA>;
to this:
for (<DATA>) { chomp; ins split /,\s*/; }
I managed to run the script on file p17226.csv (2794 lines) with apparent success.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl code for finding shortest path not working on large files (chomp)
by zing (Beadle) on Jul 26, 2014 at 07:54 UTC | |
|
Re^2: Perl code for finding shortest path not working on large files (chomp)
by zing (Beadle) on Jul 28, 2014 at 06:21 UTC | |
by Athanasius (Archbishop) on Jul 28, 2014 at 06:52 UTC | |
by zing (Beadle) on Jul 28, 2014 at 10:53 UTC | |
by QM (Parson) on Jul 28, 2014 at 12:40 UTC | |
by Athanasius (Archbishop) on Jul 28, 2014 at 13:50 UTC |