ashnator has asked for the wisdom of the Perl Monks concerning the following question:
My output is coming like this with a faulty added characters in the begining of the parsed file like this:- My faulty Output:->JAVA3_70_303NM:2:1:184:1240 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 34 40 40 40 40 40 40 4 +0 37 40 40 40 40 40 40 24 30 40 40 17 >PERL3_70_303NM:2:1:234:1166 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 4 +0 40 40 40 40 40 40 40 17 40 40 40 40 >PYTHON3_70_303NM:2:1:202:1171 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 14 40 40 13 18 40 35 3 +8 34 40 40 40 4 37 28 40 40 40 40 2
These extra (3 70 303) characters are coming in every line begining. My code is here:-JAVA3_70_303NM:2:1:184:1240 length=44 3 70 303 2 1 184 1240 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 + 34 40 40 40 40 40 40 40 37 40 40 40 40 40 40 24 30 40 40 17 PERL3_70_303NM:2:1:234:1166 length=44 3 70 303 2 1 234 1166 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 + 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 17 40 40 40 40 PYTHON3_70_303NM:2:1:202:1171 length=44 3 70 303 2 1 202 1171 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 + 14 40 40 13 18 40 35 38 34 40 40 40 4 37 28 40 40 40 40 21
Here length specifies number of times 10's or 20's or ..... occur in each record. Can you please help me to identify the problem. Thanks#!/usr/bin/perl -w use strict; $fn=$ARGV[0]; open(FD,"$fn") || die("Can't open: $!"); $/ = '>'; while ( <FD> ) { chomp; if($_=~ /(\S+)/xmsg){ my $name = $1; my @numbers = split /\D+/; my $values = @numbers; print "$name\tlength=$values\n"; print "@numbers\n"; } } close FD;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extra characters problem while parsing a file
by graff (Chancellor) on Nov 19, 2008 at 07:07 UTC | |
|
Re: Extra characters problem while parsing a file
by luckypower (Beadle) on Nov 19, 2008 at 06:50 UTC |