arrays - How to use chomp -



arrays - How to use chomp -

below have list of info trying manipulate. want split columns , rejoin them in different arrangement.

i switch lastly element of array 3rd 1 i'm running problem. since lastly element of array contains line character @ end, when switch thrid, kicks line down.

code

while (<>) { @flds = split /,/; stuff here; etc; print bring together ",", @flds[ 0, 1, 3, 2 ]; # switches 3rd element lastly }

sample data

1,josh,hello,company_name 1,josh,hello,company_name 1,josh,hello,company_name 1,josh,hello,company_name 1,josh,hello,company_name 1,josh,hello,company_name

my results - kicked downwards line.

1,josh,company_name ,hello1,josh,company_name ,hello1,josh,company_name ,hello1,josh,company_name ,hello1,josh,company_name ,hello1,josh,company_name,hello

*desired results**

1,josh,company_name,hello 1,josh,company_name,hello 1,josh,company_name,hello 1,josh,company_name,hello 1,josh,company_name,hello 1,josh,company_name,hello

i know has chomp when chomp first or lastly element, \n removed. when utilize chomp on in between, nil happens. can help?

chomp removes trailing newline argument. since none of 4 fields should actually contain newline, want purposes of info processing. can remove newline chomp before split line fields, , add together newline after each record final print statement:

while (<>) { chomp; # automatically operates on $_ @flds = split /,/; stuff here; etc; print join(",", @flds[0,1,3,2]) . "\n"; # switches 3rd element lastly }

arrays perl chomp

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -