in reply to Re^4: Perl code for finding shortest path not working on large files (chomp)
in thread Perl code for finding shortest path not working on large files

zing, the short answer is to print the user prompt to STDERR, and redirect STDOUT as you suggest above.

However, there's a more convenient way, if you're up to it. In your OP, you have the command line:

perl short_path.pl input_fie output_file

but the input and output filenames are never used in the script. To make use of them, you would access @ARGV, either explicitly or implicitly, instead of asking for the input filename.

To do so, you delete this:

print "Enter file name:\n"; chomp(my $file = <STDIN>); open(DATA,$file) or die "failed opening file!!";

Where you have:

ins split /,\s*/ for <DATA>;

replace it with this (based on Athenasius's edit):

for (<>) { chomp; ins split /,\s*/; }

The <> is Perl DWIMmery for the magic <ARGV> filehandle, which steps through all the values in @ARGV as filenames to read from, and does the open for you. (If you expect to feed the script a list of files, you may want to add some user-friendly error checking.)

Then to execute the script:

perl short_path.pl input_file > output_file

-QM
--
Quantum Mechanics: The dreams stuff is made of