By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

parsing

P: 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
Share this Question
Share on Google+
4 Replies


KevinADC
Expert 2.5K+
P: 4,059
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

P: 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
Expert 100+
P: 174
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
Expert 2.5K+
P: 3,652
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.