Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: perl6: Switch, another case (pun intended) for unscoped eval

by stefp (Vicar)
on Jul 12, 2002 at 18:25 UTC ( #181364=note: print w/replies, xml ) Need Help??


in reply to Re: perl6: Switch, another case (pun indented) for scopeless eval
in thread perl6: Switch, another case (pun intended) for unscoped eval

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

  • Comment on Re: Re: perl6: Switch, another case (pun intended) for unscoped eval
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://181364]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2021-02-28 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?