Get value of autosplit delimiter?

Looking at the source, I don't think the delimiter is saved anywhere. When you run

perl -F, -an

the lexer actually generates the code

LINE: while (<>) {our @F=split(q\0,\0);

and parses it. At this point, any information about the delimiter is lost.


Your best option is to split by hand:

perl -ne'BEGIN { $F="," } @F=split(/$F/); print join($F, @F)' foo.csv

or to pass the delimiter as an argument to your script:

F=,; perl -F$F -sane'print join($F, @F)' -- -F=$F foo.csv

or to pass the delimiter as an environment variable:

export F=,; perl -F$F -ane'print join($ENV{F}, @F)' foo.csv