468,321 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

parsing

2
hi all, i'm new to perl so any help would be much appreciated. i need to sort out this few lines(shown below) from a text file and then write to a new text file. i'm pretty confused with the regex.

; Total registers ; 0 ;
; Total pins ; 2 / 635 ( < 1 % ) ;
; Total virtual pins ; 0 ;
; Total block memory bits ; 0 / 6,617,088 ( 0 % ) ;
; DSP block 18-bit elements ; 0 / 384 ( 0 % ) ;
; Total Receiver Channels ; 0 / 8 ( 0 % ) ;
; Total ransmitter Channels ; 0 / 8 ( 0 % ) ;
; Total PLLs ; 0 / 3 ( 0 % ) ;

here's what i've tried:
Expand|Select|Wrap|Line Numbers
  1. open(INFILE, 'd:\test.fit.rpt') or die 'error';
  2. open(OUTFILE, ">output.txt") or die 'error';
  3.  
  4. while($line = <INFILE>)
  5. {
  6. chomp($line);
  7.  
  8. if ($line =~ m/[^\s]\s(\w+)[^\s]\s(\d)\s[^\s]\s(\d+)\s[^\s](\d)[^\s+]/)
  9. {
  10. print OUTFILE "$line\n";
  11. }
  12.  
  13. }
  14.  
  15. close (INFILE);
  16. Close (OUTFILE);
  17.  
Sep 25 '08 #1
4 1137
KevinADC
4,059 Expert 2GB
You need to let us know what you are trying to parse out of the lines of text you posted. Then someone can help you with suggestions or code.
Sep 25 '08 #2
tozi
2
what i need is to extract out only a few lines(which is shown as above) from a text file.
Sep 25 '08 #3
Icecrack
174 Expert 100+
you should fix up line 12 of the code above

Expand|Select|Wrap|Line Numbers
  1. Close (OUTFILE);
should be


Expand|Select|Wrap|Line Numbers
  1. close (OUTFILE);
lowercase your Perl commands.
don't forget Perl is strict.
Sep 26 '08 #4
Ganon11
3,652 Expert 2GB
In fact, make it stricter by always adding:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
to the top of your scripts.
Sep 26 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Gerrit Holl | last post: by
16 posts views Thread by Terry | last post: by
9 posts views Thread by ankitdesai | last post: by
5 posts views Thread by randy | last post: by
13 posts views Thread by Chris Carlen | last post: by
7 posts views Thread by Daniel Fetchinson | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.