On Sun, 19 Feb 2006, Bowen, Bruce wrote:

> I have a text file with lines of varying length. 
> 
> 000,;,001,WL0,001,001,000,000,000,000
> 011,@D 
> ,011,000,001,050,050,105,105,004,004,064,255,000,001,116,255,255,255,106,255,255,255,255,116,255,255,255
> 012,D,038,032,000,002,000,001,000,000
> 013,@D 
> ,013,000,001,050,050,105,105,004,004,064,255,000,001,091,255,255,255,106,255,255,255,255,091,255,255,255
> 
> According to a hex editor each line ends with a hex 0D 0A.
> 
> I can index into this file searching for items such as 012,D or 011,@D. 
>  $a = index($data, "011,[EMAIL PROTECTED]");
> 
>  What I need to do once the line is found is to isolate that one line.  I can 
> do a substr starting at the index and that eliminates all data in front of 
> the subject line, but then it contains all of the data past, to the end of 
> the file. 
>   $sub1 = substr($data, $a);
> 
>  My first attempt was to then try and index on "/\n" and that indicated it 
> could not find that character.
>   $in = index($sub1, "/\n");
> 
>   I then tried 0x0D could find that and then 0x0A and while it seemed to find 
> that character it wasn't the index was only half way into the line not at the 
> end of the line as I expected.
>   $in = index($sub1, 0x0D); result was a -1
> 
>   $in = index($sub1, 0x0A); result was 28 which if used to get a second substr
> 
>   $sub2 = substr($sub1, 0, $in);
> 
> yields 011,@D ,011,000,001,050,050,
> 
> Anyone got a clue as to what is going on?


You need to look at 'chomp'

while(<FH>){
chomp;
my $line=$_;
#do something with $line
}


Try something along those lines



Owen


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to