<>
(the diamond operator) is used in two different syntaxes.
<*.c>
, <*>
etc. is shorthand for the glob built-in function. So <*>
returns a list of all files and directories in the current directory. (Except those beginning with a dot; use <* .*>
for that).
<$fh>
is shorthand for calling readline($fh)
. If no filehandle is specified (<>
) the magical *ARGV handle is assumed, which is a list of files specified as command line arguments, or standard input if none are provided. As you mention, the perldoc covers both in detail.
How does Perl distinguish the two? It checks if the thing inside <>
is either a bare filehandle or a simple scalar reference to a filehandle (e.g. $fh
). Otherwise, it calls glob()
instead. This even applies to stuff like <$hash{$key}>
or <$x >
- it will be interpreted as a call to glob()
. If you read the perldoc a bit further on, this is explained - and it's recommended that you use glob()
explicitly if you're putting a variable inside <>
to avoid these problems.