Re: Regular Exression help



Sandy wrote:
I want to count how many + and - are there in this file.

#!/usr/bin/perl
use strict; use warnings;

my ($plus, $minus);
while (<DATA>) { #you would use a filehandle to hello.c
$plus++ if /^\+/;
$minus++ if /^\-/;
}
print "Plus: $plus \n";
print "Minus: $minus \n";


__DATA__
+ foo
- bar
+ baz
+ bap
- baq

--
http://DavidFilmer.com

.



Relevant Pages