简体   繁体   中英

How to set space as separator char while using Text::CSV::Slurp

The text file is shown as below:

Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 10.35.195.1 YES NVRAM up up
FastEthernet0/1 unassigned YES manual up down
SSLVPN-VIF0 10.35.195.1 YES unset up up
Loopback0 10.35.255.193 YES NVRAM up up
Loopback1 10.35.255.196 YES NVRAM up up
Loopback2 10.35.255.201 YES NVRAM up up
Loopback3 10.35.255.211 YES NVRAM up up

the separator char is white space instead of "," which is the default implement in Slurp . How to make it happen?

I tried sep_char as shown below, but failed.

my $data = Text::CSV::Slurp->load(file => 'table.txt',sep_char >= 0x20);

You have a syntax issue.

That should be a => after sep_char , not >= . Also, a simple sep_char => ' ' should be sufficient (instead of 0x20 ).

The Text::CSV::Slurp uses the Text::CSV module to parse the lines of the file. The load method you used passes the options to the constructor of Text:CSV , you may have a typo:

my $data = Text::CSV::Slurp->load(file => 'table.txt', sep_char => ' ');

IMPORTANT: Text::CSV_XS is not designed to detect the characters used to quote and separate fields. The parsing is done using predefined settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM