and i would like to count how many CAPITAL letters there are until the first non-word character. so that i can cut the string using "substr" to get exactly the portion that i want..is this possible??
You can probably do that with a regular expression, but I'm not good enough with regular expressions to know how to do that. I'd use the "brute force" method:
my @chars = split //, $a;
my $ct = 0;
my $pos = 0;
foreach (@chars) {
if (/\W/) { ### if hit a non-word character
$pos = $ct;
last;
}
$ct++;
}
### now $pos contains the position of the 1st non-word char.
Beware - I haven't tested this at all - I'm not entirely sure that \W means non-word character, and I'm not positive on the split. You want to split on nothing, so that each character will end up in a separate array element.
Is it possible that you might have lower case alphas prior to the first non-word char? If so,
$str =~ /(.*?)\W/; # catch chunk prior to first non-word char in $1.
$chunk = $1;
while ($chunk =~ /[A-Z]/g) { $cnt++; } # count upper case alphas in chunk
but i ended up figuring out a way to solve the prob on my own...there was a ";" just before the string i wanted so i used the "split" method to extract the part that i was looking for
ie:
($x, $y, $z) = split/(/, $a;
where $a is the string i wanted to split
& it worked perfect!!
Q1. After that statement, I know that $1 will contain the value in parenthesis, but will that statement "change" $a?
Q2. Is there a way to make a regular expression just get the *length* of the match it finds? Using barley's example, if you wanted to get the length of the matches substring, you'd have to first "get" the substring you're interested in(which the above regex gets into $1), and then you'd have to get the length of $1 - 2 step process.
Hardy Merrill
Mission Critical Linux, Inc.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.