in reply to Capture uncommented keywords
Is there another way?
Remove comments from the input before matching.
For trivial code containing only // comments (not /* */) and without string constants containing //, the following should do the trick:
#!/usr/bin/perl use strict; use warnings; while (<>) { chomp; my $orig=$_; s|//.*||; # strip comments if (/\b(printf|scanf|open|close|read|write)\b/) { print "Found keyword '$1' in '$_'.\nOriginal line: '$orig'\n"; } }
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Capture uncommented keywords
by ExReg (Priest) on Jul 28, 2015 at 18:23 UTC |