Hi

Is it possible to externally disable warnings within the scope of an already compiled code-block?

That is without manipulating $SIG{__WARN__}³ or to deparse and reevalute the code?

Maybe using some B magic?

motivation

I'm playing around to mimic the for LIST -> variables feature of Perl6¹, but with more syntactic sugar, than splice or natatime can provide.

One of my attempts looks like this and kinda works...

implementation:

model:

my @a=1..10; # update2 for (1..3) { from {@a} loop { set my ($a,$b,$c); print "(",$a,$b,$c,")"; # no warnings 'exiting'; # last; }; print "\n"; } __END__ (123)(456)(789)(10) (123)(456)(789)(10) (123)(456)(789)(10)

...but while using loop-control statements like last works (amazing²) it throws a warning which needs to be silenced.

I could refrain to adding new pseudo statements like xlast() but this break in orthogonality would confuse too much.

Manipulating the sig-handler adds to much overhead, using B::Deparse is somehow risky, cause it's not bug-free.

I think this is of general interest for those playing around with syntactic sugar. :)

Cheers Rolf

( addicted to the Perl Programming Language)

update

¹) from perlcabal

This can be extended to take more than one element at a time: Was: while (my($age, $sex, $location) = splice @whatever, 0, 3) + { ... } Now: for @whatever -> $age, $sex, $location { ... } (Except the for version does not destroy the array.)

²) ...and disturbing ... and scaring ... and Perl! ;-)

³) for completeness

$SIG{__WARN__}= sub { return if $_[0] =~ /^Exiting subroutine/; warn $_[0]; };

update2

Put initialization of @a to the start to show that the from-loop reinitializes each time, even if broken with last.


In reply to Silencing specific warnings when executing coderef? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.