Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] searching for pattern maching #ifdef or #ifndef in c source file

Expand Messages
  • Nicck_par
    Thanks alot..!!!! can i also transfer these symbols and its values to the excel format...!!!! Bye, Nicck ... The operator only returns one line from the
    Message 1 of 4 , Nov 5, 2004
    • 0 Attachment
      Thanks alot..!!!!

      can i also transfer these symbols and its values to the excel format...!!!!

      Bye,
      Nicck

      Jeff Eggen <jeff.eggen3@...> wrote:
      >open(INFILE,$ARGV[0]);
      >$inline=<INFILE>;
      >if ($inline =~ /^#ifdef/){
      >print $&;}
      >elsif($inline =~ /^#ifndef/){
      >print$&;}
      >else{print("ther are not more symboles.\n");}

      The <> operator only returns one line from the file in scalar context. You
      only have one line of the file in your $inline variable. If you want to
      print out the lines that start with #ifdef or #ifndef, you could just cycle
      through the file one line at a time:

      # Begin code
      while (<>) # perldoc perlop
      {
      print if (m/^#ifn?def); # perldoc -f print, perldoc perlretut
      }
      print "There are no more symbols.\n";
      # End code

      Since the input file(s) are listed on the command line as arguments, you can
      do an implicit open on them, and since the two strings you are searching for
      are very close you can get by with one pattern that will match either one.
      This solution also avoids using $&, which as perlvar will tell you is a
      large performance hit. Anyhoo, read up on the perldocs I listed above, and
      it should all make sense.

      Hope this helps,
      Jeff Eggen



      Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html


      Yahoo! Groups SponsorADVERTISEMENT


      ---------------------------------
      Yahoo! Groups Links

      To visit your group on the web, go to:
      http://groups.yahoo.com/group/perl-beginner/

      To unsubscribe from this group, send an email to:
      perl-beginner-unsubscribe@yahoogroups.com

      Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



      ---------------------------------
      Do you Yahoo!?
      Check out the new Yahoo! Front Page. www.yahoo.com/a

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.