in reply to Re: Does Perl 5 (or 6?) need another built-in variable for the -F switch?
in thread Does Perl 5 (or 6?) need another built-in variable for the -F switch?
This is wrong on several accounts. First, inside the one-liner, you need to place quotes around $F, otherwise, at best you end up with bare words, but more likely, you end up with something that cannot be compiled (Try F=":") for instance. Second, the shell doesn't know "\t" as something special. It just sees an escaped t, and hence, F="\t" is equivalent to "t".join(t, @F)
Also, the command line switches -line won't do what you expect it to do. It means "chomp of newlines, and add newlines to print, and modify the input file, leaving a backup with extension 'ne'".
You probably want (untested):
F=' ' # Enter a tab here. perl -F"$F" -i -wlne "munge(@F); print join('$F',@F);" file
But you can to better, it can also work if you want to use single quotes for the one liner. The shell's quoting mechanism are superior to Perls in some expects. Exploit them:
perl -F"$F" -i -wlpe 'munge(@F); $_ = join("'$F'",@F);'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Does Perl 5 (or 6?) need another built-in variable for the -F switch?
by jbert (Priest) on Nov 03, 2006 at 10:01 UTC | |
by Anonymous Monk on Nov 03, 2006 at 11:47 UTC | |
by jbert (Priest) on Nov 03, 2006 at 12:30 UTC |