Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a bug with Perl's glob prototype?
    text
    copied!<p>For no particular reason, I was playing around with the glob prototype <code>(*)</code>, and seeing what it would do when the argument is a defined subroutine.</p> <p>Given the following code:</p> <pre><code>sub test (*) {print "[@_]\n"} sub blah ($) {"blah got @_"} </code></pre> <p>If you write <code>test blah;</code> you get the syntax error <code>Not enough arguments for main::blah...</code></p> <p>If you write <code>test blah 1;</code> the program compiles and prints <code>[blah]</code></p> <p>If you write <code>test blah die;</code> the program compiles, prints <code>[blah]</code> and does NOT die.</p> <p>If you write <code>test blah(1);</code> the program compiles and prints <code>[blah got 1]</code></p> <p>If you write <code>test blah(die);</code> the program compiles and then dies.</p> <p>The last two examples are clearly an application of the "if it looks like a subroutine call it is a subroutine call` rule. </p> <p>However, the parenthesis-less examples seem like a bug to me. Because what seems to be happening is that despite being in glob context, the parser still treats <code>blah</code> as a prototyped function that requires an argument. But when compilation is said and done, the argument to <code>blah</code> is completely thrown away, and the string <code>'blah'</code> is instead passed to <code>test</code>.</p> <p>Here is an example of the <code>test blah die;</code> construct run through <code>B::Deparse</code>:</p> <pre><code>$ perl -MO=Deparse,-p -e 'sub test (*) {print "[@_]\n"} sub blah ($) {"blah got @_"} test blah die;' sub test (*) { print("[@_]\n"); } sub blah ($) { "blah got @_"; } &amp;test('blah'); -e syntax OK </code></pre> <p>So as you can see, the <code>die</code> is completely dropped from the op-tree.</p> <p>So my question is if others consider this behavior a bug? Is the behavior documented anywhere? If it is a bug, is it worth fixing?</p>
 

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