Perl command line autosplit vs //

I often use autosplit Perl instead of shorthand on the command line. I ended up in a case where I have many gaps that I need to keep. According to the document, the separator I need to specify is / /because things like ' 'emulate awk behavior, stripping leading spaces, etc.

My problem is the inability to specify a template / /on the command line. I tried to quote it in different ways, but the splitting ends with a slash:

perl -F'/ /' -lane 'print "@F[3..$#F]"' input.txt

The following works as expected:

perl -lne '@ar = split / /; print "@ar[3..$#ar]"' input.txt

Why is my auto-extension not working and how to fix it?

Perl 5.8.8 on RHEL 5.9.

+4
source share
2 answers

" ":

perl -F\\x{20} ...
perl -F\\040   ...
+6

, , . , split /(\s+)/ - , .

,

  x  x  x

(thats "\x20\x20x" x 3)

,

perl -MData::Dump -F/(\x20+)/ -anE"dd \@F" data.txt

["", "  ", "x", "  ", "x", "  ", "x\n"]

?

0

Source: https://habr.com/ru/post/1530114/


All Articles