What does the following segment of code output? [code] $string1 = "Hello World\n"; if ($string1 =~ m/(H..).(l..)/) { print "We matched '$1' an

Việt Quân

New member
What does the following segment of code output?
Code:
$string1 = "Hello World\n";
if ($string1 =~ m/(H..).(l..)/) {
  print "We matched '$1' and '$2'.\n";
}
A. We matched ‘Hel’ and ‘ld’
B. We matched ‘Hel’ and ‘lld’
C. We matched ‘Hel’ and ‘lo ‘
D. None of the mentioned
 
Answer: C
Explanation: () groups a series of pattern element to a single element.
When we use pattern in parenthesis, we can use any of ‘$1’, ‘$2’ later to refer to the previously matched pattern.
 

Tìm kiếm

Back
Top