[pm-h] relocate metatags in hyperlatex-generated HTML

G. Wade Johnson gwadej at anomaly.org
Tue Feb 13 20:09:57 PST 2007


On Tue, 13 Feb 2007 18:10:53 -0600
"Russell L. Harris" <rlharris at oplink.net> wrote:

> Success!  The following code does the job of relocating the meta tags:

Congrats.


> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[snip]

> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> 
> However, looking at the code, I see that I don't understand the
> working of the diamond operator in the context of the while structure.
> 
> Following is the explanation which I have been able to piece together
> regarding of the diamond operator:
> 
>     The diamond operator <filehandle> is the line-input operator; when
>     empty ( <> ), the diamond operator reads from the ARGV filehandle,
>     which reads the array of filenames from the Perl command line.
>     Each invocation of <> returns as a string from the filehandle the
>     next record of the file (as determined by the input record
>     separator), until the end of the file is reached, at which point
>     <> returns undef.
> 
> It appears that each of the three pattern-matching operators within
> while structure is able to read the file from start to finish.  So it
> appears that, in this context, the while structure is acting simply as
> a "file open" mechanism, rather than a mechanism which steps through a
> file record by record.

Not quite. The diamond operator is reading a string from the file up to
the input record separator. However, this code contains a small piece
of magic right before the while...the line

undef $/;

The $/ variable contains the input record separator. By undefining it,
we have told Perl we want to read until the end of the file. This is
sometimes called "slurp mode". So, the result is that each call to <>
returns the entire file as a string.

With multiple files on the command line, the while loop will process
one file per pass, which is exactly what you want.

> 
> And what happens if I should invoke the script with the command line:
> 
>     $ ./metamove.pl *.html
> 
> rather than
> 
>     $ ./metamove.pl just_one_file.html
> 
> ?  The documentation I thus far have found appears to say that <>
> reads a series of files as if they were a single contiguous file.

Sort of. <> returns each record of the first file. Then, when the first
file is finished, it moves on to the second file, etc. In slurp mode,
The entire first file is a record. Then we move to the second file and
treat it as one record, etc.

G. Wade
-- 
"The avalanche has already started. It is too late for the pebbles to
vote."                               -- Ambassador Kosh, "Believers"


More information about the Houston mailing list