I just started on learning perl, and in the sample code given by my book there is this line:
#!/usr/bin/perl
@lines = `perldoc -u -f atan2`;
foreach (@lines) {
s/\w<([^>]+)>/\U$1/g;
print;
}
the code works, that’s not the problem. Also by observing the input and output I know that this line:
s/\w<([^>]+)>/\U$1/g;
does this
ATAN2 ARCTANGENT TAN TANGENT <--- X<atan2> X<arctangent> X<tan> X<tangent>
and this
MATH::TRIG::TAN <------- C<Math::Trig::tan>
My question is: where does the X and the C come from?
As an FYI: here is my output if I don’t use the code:
perldoc -u -f atan2
=over 8
=item atan2 Y,X
X<atan2> X<arctangent> X<tan> X<tangent>
Returns the arctangent of Y/X in the range -PI to PI.
For the tangent operation, you may use the C<Math::Trig::tan>
function, or use the familiar relation:
sub tan { sin($_[0]) / cos($_[0]) }
The return value for C<atan2(0,0)> is implementation-defined; consult
your atan2(3) manpage for more information.
=back
And here is the complete output from the code:
[/cygdrive/c/Users/Documents/learn_perl]$ ./hello_world.pl
=over 8
=item atan2 Y,X
ATAN2 ARCTANGENT TAN TANGENT
Returns the arctangent of Y/X in the range -PI to PI.
For the tangent operation, you may use the MATH::TRIG::TAN
function, or use the familiar relation:
sub tan { sin($_[0]) / cos($_[0]) }
The return value for ATAN2(0,0) is implementation-defined; consult
your atan2(3) manpage for more information.
=back
The substitution regex
Finds an alphanumeric character (X and C in the sample text), followed by
<, captures any characters that are not>, followed by a>. Then it puts the captured string back, with the escape sequence\Uwhich turns it into upper case.They were already in the perldoc text. They were however removed by the substitution regex. Perhaps you got input and output confused.