>On Jun 25, Sally said:
>
> >when evaluating strings what exactly does /g do at the end of a lot of
> >evaluation expressions eg:
> >
> >$string =~ /(.)/g

my $string = "abcd a bcd ab cd";
$string =~ /a/; # finds the first "a" - the a in 'abcd'

$string =~ /a/g; # finds all "a"'s in the string

The second example is mostly useful if you want to find out how many times 
a pattern is repeated in a string:
my $lCount = () = $string =~ /a/g; # $lCount now equals how many times the 
string matched, in this case 3

of if you want an array of all the substrings that are the matches:
my @asMatches = $string =~ /a/g; # @asMatches is now an array containing 3 
elements, each of which is equal to "a"


Aaron Craig
Programming
iSoftitler.com

Reply via email to