To find out if XYZ occurs once and only once, I thought it would work using:
if ($string =~ /(XYZ){1}/)
I thought the condition should be FALSE as {1} is a quantifier that is described in my documentation as "exactly 1 times".
But XYZ occurs 2 times.
However the condition is TRUE in my testing. I just don't get it.
Also, is m!regexp! same as /regexp/ but the former used for legibility?
Thanks
Tom
if ($i == $good_number){ print "good\!\n"; }
else {
print "bad, $search_word is in there $i, which is not right\n"
}
Thanks, I'll test your suggestion out.
However I don't understand what you mean by "Using the {number} will only show true if it is matched up, it isn't good for counting.".
So what would the difference be between m!(XYZ){1}! and m!(XYZ){2}!
I looked at more 'quantifiers', specifically {i,j} which is described as "at lease i times and at most j times".
So I tried m!(XYZ){1,1}! which to me means return TRUE if XYZ is found at least 1 times and at most 1 times. But that did not work.
Obviously I am misunderstanding something fundamental here.
gsx
Your suggestion came up after I posted this reply, so I'm editing my reply. Thanks also.
++++++++++++++++++
Also, is m!regexp! same as /regexp/ but the former used for legibility?
Tom
Also, is m!regexp! same as /regexp/ but the former used for legibility?
Itīs the same. Using the m style letīs you use any delimiter. That way you can choose one thatīs not in your expression to avoid having to escape it.
/\/path\/to\/file/ is a lot harder to read than m{/path/to/file}.
So what would the difference be between m!(XYZ){1}! and m!(XYZ){2}!
The former will match "XYZ", "XYZXYZ", "XYZXYZXYZ", etc while the latter will start matching with the "XYZXYZ".
To find the number of occurances of pattern in string use something like
my $c = 0;
while (m!pattern!g) {
$c++;
}
To test those things for yourself you might want to use perl from the command line like this:
perl -e '$_="XYZXYZ"; print scalar(/(XYZ){1}/);'