http://qs1969.pair.com?node_id=587284

Andrew_Levenson has asked for the wisdom of the Perl Monks concerning the following question:

I have a certain script that I have been working with for a while now, watching it evolve as I learn new things. It really doesn't do anything important except for helping me understand new concepts as I implement them.

Today I learned of the ?: operator, and decided to implement it. Now, when I introduce the input and output files and command line arguments, this works perfectly. However, if I don't, and include them as input, it tells me that the argument is invalid and contains a newline.

Can anyone tell me why the newline character is not being removed like it has in all four preceding iterations of this script? (Only the input lines have been changed.)

use strict; use warnings; $_[0]=!@ARGV?<>:shift @ARGV; $_[1]=!@ARGV?<>:shift @ARGV; handlefix(); open(INFILE, '<', $_[0]) or die "\nCan't open $_[0]: $!\n"; open(OUTFILE, '>', $_[1]) or die "\nCan't open $_[1]: $!\n"; print OUTFILE map { my $s=$_; $s=~s/\s*#.*$//; $s } (grep { !/^\s*#/ } <INFILE>), "\n" ; close INFILE && close OUTFILE; sub handlefix { for(@_){ chomp($_); $_=~s/"//g; $_=~s/\//\\/g; } }

Thanks in advanced!