in reply to Re: Open file & Strip comma delimiter
in thread Open file & Strip comma delimiter
Why is printing for example "\\00004DA5.005|" the extra stuff. I only need $fields10..5|H:\<subdir>\<file.ext>' I'll appreciate your help I modified the code that you send me as follows:print"463694|BROOKS JR|JAMES|Arnold Markoe|1/17/03|MD Wkly Note|H:\17 +\00004DA5.0057\\00004DA5.005| 479309|WALDMAN|MELVI|Arnold Markoe|1/17/03|MD Wkly Note|H:\16\00004DE0 +.0056\\00004DE0.005|\n";
print "#! perl -w use strict; my $infile = 'c:/doclist.chr'; my $outfile = 'c:/doclist.txt'; #use File::Find; #use File::Copy cp; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; ## print OUT join '|', split /,/ while <IN>; while(<IN>) { chomp; my @fields = split /,/; my $string1 = $fields[6]; do { warn "Empty field 7"; next } unless $string1; # this will keep the first 24 chars of string, throw out the rest a +nd # then append H:\ to it. # need \\ here or it won't compile my $string_header = $string1; substr($string_header,0,24) = 'H:'; # this will return :\ as we get 2 chars LEN from pos 25 my $string2 = substr($string1,26,2); # this will set $string3 to the last 13 chars of the string my $string3 = substr($string1,-13); my $finstring = $string_header.$string2.$string3; my $out = join '|', @fields[0..5], $finstring, "\n"; print OUT $out; } exit; \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Open file & Strip comma delimiter
by tachyon (Chancellor) on Feb 17, 2003 at 02:42 UTC | |
by skyler (Beadle) on Feb 17, 2003 at 04:08 UTC | |
by tachyon (Chancellor) on Feb 17, 2003 at 05:28 UTC |