Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>parse(*ARGV)</code> is the simplest solution: the explanation is a bit long, but an important part of learning how to use Perl effectively is to learn Perl.</p> <p>When you use a null filehandle (<code>&lt;&gt;</code>), it actually reads from the magical <code>ARGV</code> filehandle, which has special semantics: it reads from all the files named in <code>@ARGV</code>, or <code>STDIN</code> if <code>@ARGV</code> is empty.</p> <p>From <code>perldoc perlop</code>:</p> <blockquote> <p>The null filehandle <code>&lt;&gt;</code> is special: it can be used to emulate the behavior of sed and awk. Input from <code>&lt;&gt;</code> comes either from standard input, or from each file listed on the command line. Here’s how it works: the first time <code>&lt;&gt;</code> is evaluated, the <code>@ARGV</code> array is checked, and if it is empty, <code>$ARGV[0]</code> is set to <code>"-"</code>, which when opened gives you standard input. The <code>@ARGV</code> array is then processed as a list of filenames. The loop</p> <pre><code>while (&lt;&gt;) { ... # code for each line } </code></pre> <p>is equivalent to the following Perl-like pseudo code:</p> <pre><code>unshift(@ARGV, '-') unless @ARGV; while ($ARGV = shift) { open(ARGV, $ARGV); while (&lt;ARGV&gt;) { ... # code for each line } } </code></pre> <p>except that it isn’t so cumbersome to say, and will actually work. It really does shift the <code>@ARGV</code> array and put the current filename into the <code>$ARGV</code> variable. It also uses filehandle <code>ARGV</code> internally--<code>&lt;&gt;</code> is just a synonym for <code>&lt;ARGV&gt;</code>, which is magical. (The pseudo code above doesn’t work because it treats <code>&lt;ARGV&gt;</code> as non-magical.)</p> </blockquote> <p>You don't have to use <code>&lt;&gt;</code> in a <code>while</code> loop -- <code>my $data = &lt;&gt;</code> will read one line from the first non-empty file, <code>my @data = &lt;&gt;;</code> will slurp it all up at once, and you can pass <code>*ARGV</code> around as if it were a normal filehandle.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload