Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
hello everyone, i had been trying to make a lexical analyzer for c, where all the keywords were to be inputted in a text file keywords. this i stored in an array. but this process is not being automated. the code i wrote is as follows :-
#!/usr/bin/env perl @keywd=`cat /home/vikash/maya/keywords`; @operatr=`cat /home/vikash/maya/operators`; print "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +>"; foreach $keyword (@keywd){print "$keyword";} print "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +>"; print "\nthe total no. of keywords specified in the file are :($#keywd +)\n"; print "hello $ENV{'USER'}, greetings !!! you are "; print "using display $ENV{'DISPLAY'} \n"; $file='/home/vikash/maya/new.c'; print "\n\n:Lexical Analysis Report:\n\n"; print " |-> Input Code File:- $file\n"; print <<"EOF"; \nThe code used in the lexical analysis is :- \n EOF print `cat /home/vikash/maya/new.c`; for($i=0;$i<$#keywd;$i++) { print if /\b^int$\b/; } __END__
the keywords file contains:- auto continue enum if short break switch volatile default extern int signed typedef while case do float long sizeof union char double for register static unsigned const else goto return struct void the problem i'm having is that the keywords are not being taken automatically one after the another from this list of keywords............. if i do
open(INFO,$file); while(<INFO>){ print if /\bint\b/; print if /\bfloat\b/; } close(INFO)
everything's fine........ but i don't want to enter all these keywords one by one. what if in future i were to add a new keyword. i would simply like to modify the keywords file not the whole code........

In reply to how to automate the regular expression match from a file? by vikashiiitdm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-26 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found