Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Certainly enums should be programmed as a filter since stacking filters is allowed.

After filtering by Switch, my program becomes what is listed below and the subroutine Switch::case is called with my regexp as parameter. So, my bad, this seems to be a case for unscoped sub instead of unscoped eval. BTW: I am peeking at parrot and is positively impressed.

use Carp; sub enum { my @enum = split /,/, $_[0]; my $i = 0; for ( @enum ) { S_W_I_T_C_H: while (1) { local $::_S_W_I_T_C_H; Switch::switch ( +$_); if (Switch::case qr/([A-Z]+\d*)(?:\s*=\s*(\d)+)?/i){ while (1) +{ m/([A-Z]+\d*)(?:\s*=\s*(\d)+)?/i; no strict; $i = $2 if defined $2; eval "sub $1() { $i }"; $i++; ;last S_W_I_T_C_H } continue { goto C_A_S_E_1 } last S_W_I_T_C_H; +C_A_S_E_1: } else { croak qq(bad enum member syntax: "$_") } }continue {last} } } enum "INFIX, PREFIX=4, SUFFIX" ; print INFIX(), ":", PREFIX(), ":", SUFFIX(), "\n";

-- stefp -- check out TeXmacs wiki


In reply to Re: Re: perl6: Switch, another case (pun intended) for unscoped eval by stefp
in thread perl6: Switch, another case (pun intended) for unscoped eval by stefp

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-18 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found