2016User1 has asked for the wisdom of the Perl Monks concerning the following question:
Hi. Other than following somebody else's suggestions for lines of Perl (Practical extraction and reporting language) code to correct, I don't think I have ever written a full script in Perl and don't know much about the Perl interpreter. Currently I have Perl 5.18.2 installed in a 64-bit, openSUSE Leap, 42.1 Linux operating system. A Perl subroutine written by other people and with a name of the form “make_....._href” that begins with the line of code of the form ''sub make_...._href {'' ends with a line of code looking like ''<A NAME=...... HREF=......>...</A>'';}, or text enclosed by a pair of double-quotation marks, as well as a closing semicolon for I suppose the line of code and a closing right brace to complement the opening left brace and complete the enclosure of the subroutine's contents. I suspect that the purpose of such a line of code is to eventually facilitate the writing of at least a portion of a line in a .html (HyperText Markup Language), output file which at least sometimes may include a hyperlink to a different Web page or else to a location on the same Web page. But I don't think the line ''<A NAME=...... HREF=......>...</A>''; all by itself will enable any such writing to be performed in a .html file! Where should I be looking for the explicit command for such writing of that line in the .html, output file? I suspect that a built-in function of Perl might be involved in such writing. Do you, hopefully an experienced Perl programmer, agree with this guess of mine? Is there a built-in Perl subroutine with a name ending in href? And if so, how may I see its lines of code?
Re: Where is the writing being done in a .html, output file corresponding to the Perl subroutine line "<A NAME=.... HREF=...>...</A>";?
by LanX (Saint) on Mar 14, 2016 at 17:07 UTC
|
Welcome to the monastery! :)
> ends with a line of code looking like ''<A NAME=...... HREF=......>...</A>'';}
Perl subroutines can implicitly return the last value/statement without explicit return statement.
see perlsub
If no return is found and if the last statement is an expression, its value is returned. If the last statement is a loop control structure like a foreach or a while , the returned value is unspecified. The empty sub returns the empty list.
This is done to facilitate functional programming.
So the writing is done where the function is called.
| [reply] [d/l] |
Re: Where is the writing being ordered for within a .html, output file corresponding to the Perl subroutine line "<A NAME=.... HREF=...>...</A>";?
by Anonymous Monk on Mar 14, 2016 at 17:20 UTC
|
As LanX already said, that string ("<A NAME=... HREF=...>...</A>") is likely being returned from the subroutine. So you should look for the place where the subroutine is being called. For example, it may say something similar to print $fh make_href();, in which case the string will be printed to the filehandle $fh, or something like my $var = make_href();, in which case the string is being stored in the variable $var for further processing and probably eventually printing. If you could show some actual code, that would help in answering your question better - see http://sscce.org/
| [reply] [d/l] [select] |
|
Thanks, Rolf and Anonymous Monk, for kindly and so quickly posting some information for me. Your postings make a good beginning for me! You seem to be good teachers! The Perl script written by other people that I have been inspecting contains numerous subroutines. And my knowledge of Perl is little. Perhaps I need to learn more about Perl to understand the code I have been inspecting.
| [reply] |
|
| [reply] |
|