parsing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tozi
    New Member
    • Sep 2008
    • 2

    parsing

    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:
    Code:
    open(INFILE, 'd:\test.fit.rpt') or die 'error';
    open(OUTFILE, ">output.txt") or die 'error';
    
    while($line = <INFILE>)
    {
    chomp($line);
    
    if ($line =~ m/[^\s]\s(\w+)[^\s]\s(\d)\s[^\s]\s(\d+)\s[^\s](\d)[^\s+]/)
    {
    print OUTFILE "$line\n";
    }
    
    }
    
    close (INFILE);
    Close (OUTFILE);
    Last edited by numberwhun; Sep 25 '08, 12:34 PM. Reason: Please use code tags
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    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.

    Comment

    • tozi
      New Member
      • Sep 2008
      • 2

      #3
      what i need is to extract out only a few lines(which is shown as above) from a text file.

      Comment

      • Icecrack
        Recognized Expert New Member
        • Sep 2008
        • 174

        #4
        you should fix up line 12 of the code above

        Code:
        Close (OUTFILE);
        should be


        Code:
        close (OUTFILE);
        lowercase your Perl commands.
        don't forget Perl is strict.

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          In fact, make it stricter by always adding:

          [code=perl]use strict;
          use warnings;[/code]

          to the top of your scripts.

          Comment

          Working...