My test file has an "n" number of lines, and there is ^ M between each line, which in turn makes it one large line. The code I'm working with opens the specified file and needs to parse the header and then the subsequent lines, and then look for the directory path and file name. But since the file just ends up as a large line, it does not work correctly
#!/usr/bin/perl #use strict; #use warnings; open (DATA, "<file.txt") or die ("Unable to open file"); my $search_string = "Directory Path"; my $column_search = "Filename"; my $header = <DATA>; my @header_titles = split /\t/, $header; my $extract_col = 0; my $col_search = 0; for my $header_line (@header_titles) { last if $header_line =~ m/$search_string/; $extract_col++; } for my $header_line (@header_titles) { last if $header_line =~m/$column_search/; $col_search++; } print "Extracting column $extract_col $search_string\n"; while ( my $row = <DATA> ) { last unless $row =~ /\S/; chomp $row; my @cells = split /\t/, $row; $cells[74]=~s/:/\//g; $cells[$extract_col]= $cells[74] . $cells[$col_search]; print "$cells[$extract_col] \n"; }
When I open the test file in VI, I used
:%s/^M/\r/g
and what removes ^ M, but how to do this in this perl program? When I tried the test program and inserted it s\^M/\r/g and wrote it in another file, she got a lot of Chinese characters.
source share