I think choroba’s point is that you can use BEGIN blocks to determine when the warning is issued. For example:
#! perl
use strict;
use warnings;
BEGIN { print "BEGIN 1\n"; }
sub each { warn 'main::each() was called' }
BEGIN { print "BEGIN 2\n"; }
sub delete { warn 'main::delete() was called' }
BEGIN { print "BEGIN 3\n"; }
my %person = (name => 'Ken Takakura');
while (my ($key, $val) = each %person)
{
print "$key: $val\n";
}
delete $person{name};
BEGIN { print "BEGIN 4\n"; }
produces this output:
BEGIN 1
BEGIN 2
BEGIN 3
Ambiguous call resolved as CORE::each(), qualify as such or use & at 1
+66_SoPW.pl line 13.
BEGIN 4
name: Ken Takakura
which shows that the warning is issued during the compile phase (before the main code is executed) at the point where the code specifies an ambiguous call to each.
This works because BEGIN blocks are executed during compilation, as soon as they are seen by the Perl compiler, before the main code is run. See BEGIN, UNITCHECK, CHECK, INIT and END.
HTH,
Athanasius <°(((>< contra mundum
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|