in reply to how to automate the regular expression match from a file?
use Data::Dumper; use strict; my @keywords = qw(auto continue enum if short break switch volatile de +fault extern int signed typedef while case do float long sizeof union + char double for register static unsigned const else goto return stru +ct void); my $keywords_re = join '|', @keywords; my $file = '/home/vikash/maya/new.c'; open my $fh, $file or die $!; my %keywords; while (<$fh>) { while (m{\b($keywords_re)\b}g) { $keywords{$1}++; } } print Dumper(\%keywords);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to automate the regular expression match from a file?
by vikashiiitdm (Novice) on Apr 07, 2011 at 07:23 UTC |