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, |
In reply to Re: Perl code for finding shortest path not working on large files (chomp)
by Athanasius
in thread Perl code for finding shortest path not working on large files
by zing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |