Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two assignment operators: list assignment and scalar assignment. The choice is determined based on the LHS of the "<code>=</code>". (The two operators are covered in detail in <a href="http://www.perlmonks.org/?node_id=790129" rel="nofollow">here</a>.)</p> <hr> <p>In this case, a list assignment operator is used. The list assignment operator evaluates both of its operands in list context.</p> <p>So what does <code>$_=~ /^&gt;(.*)/</code> do in list context? Quote <a href="http://perldoc.perl.org/perlop.html" rel="nofollow">perlop</a>:</p> <blockquote>If the <code>/g</code> option is not used, <code>m//</code> in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, i.e., (<code>$1</code>, <code>$2</code>, <code>$3</code>...) [...] When there are no parentheses in the pattern, the return value is the list <code>(1)</code> for success. With or without parentheses, an empty list is returned upon failure.</blockquote> <p>In other words,</p> <pre><code>my ($match) = $_ =~ /^&gt;(.*)/; </code></pre> <p>is equivalent to</p> <pre><code>my $match; if ($_ =~ /^&gt;(.*)/) { $match = $1; } else { $match = undef; } </code></pre> <hr> <p>Were the parens omitted (<code>my $tmp = ...;</code>), a scalar assignment would be used instead. The scalar assignment operator evaluates both of its operands in scalar context.</p> <p>So what does <code>$_=~ /^&gt;(.*)/</code> do in scalar context? Quote <a href="http://perldoc.perl.org/perlop.html" rel="nofollow">perlop</a>:</p> <blockquote>returns true if it succeeds, false if it fails.</blockquote> <p>In other words,</p> <pre><code>my $matched = $_ =~ /^&gt;(.*)/; </code></pre> <p>is equivalent to</p> <pre><code>my $matched; if ($_ =~ /^&gt;(.*)/) { $matched = 1; # !!1 if you want to be picky. } else { $matched = 0; # !!0 if you want to be picky. } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    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