In awk I can write: awk -F: 'BEGIN {OFS = FS} ...'
In Perl, what’s the equivalent of FS? I’d like to write
perl -F: -lane 'BEGIN {$, = [what?]} ...'
update with an example:
echo a:b:c:d | awk -F: 'BEGIN {OFS = FS} {$2 = 42; print}'
echo a:b:c:d | perl -F: -ane 'BEGIN {$, = ":"} $F[1] = 42; print @F'
Both output a:42:c:d
I would prefer not to hard-code the : in the Perl BEGIN block, but refer to wherever the -F option saves its argument.
To sum up, what I’m looking for does not exist:
-F, and more importantlyNote that the same holds true in awk:
FSis a string but acts as regex:outputs "
a[:,]42[:,]c[:,]d"Thanks for the insight and workarounds though.
You can use perl’s
-s(similar to awk’s-v) to pass a "FS" variable, but thesplitbecomes manual: