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!

In reply to Invalid argument by Andrew_Levenson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.