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.)
Thanks in advanced!
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Invalid argument
by suaveant (Parson) on Dec 01, 2006 at 20:26 UTC | |
by Andrew_Levenson (Hermit) on Dec 01, 2006 at 20:31 UTC | |
by suaveant (Parson) on Dec 01, 2006 at 20:40 UTC | |
Re: Invalid argument
by blokhead (Monsignor) on Dec 01, 2006 at 20:27 UTC | |
by Andrew_Levenson (Hermit) on Dec 01, 2006 at 20:34 UTC | |
Re: Invalid argument
by liverpole (Monsignor) on Dec 01, 2006 at 20:19 UTC | |
by Andrew_Levenson (Hermit) on Dec 01, 2006 at 20:21 UTC | |
by liverpole (Monsignor) on Dec 01, 2006 at 20:30 UTC | |
by grep (Monsignor) on Dec 01, 2006 at 20:27 UTC |
Back to
Seekers of Perl Wisdom