Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Perl: the Markov chain saw
 
PerlMonks  

Re: Poor Man's Perl6 Exegesis (you get what you pay for)

by mikfire (Deacon)
on Jan 24, 2002 at 21:09 UTC ( #141247=note: print w/ replies, xml ) Need Help??


in reply to Poor Man's Perl6 Exegesis (you get what you pay for)

I will take a pass at this for loop:

for(@options) { my($sign, $name, $value)=/[+-]([[\w]&&[^\d]]\w+)(?:=(.*))?/s; # this looks like a typo - there should be parens around # the [+-]? my $targ := ${$Exporter::From::{$name}}; given($sign) { when('+'): { if(defined $value) { $targ=$value; } else { $targ is true; } } when('-') { if($targ.props{true}) { $targ is false; } else { undef $targ; } } } }
If I have understood what I have read ( which is a mighty large conditional ), the first two lines are pretty much identical to any perl5 code. The third line creates an alias between the $targ and the variable in Exporter::From symbol table ( which looks to be a really, really neat feature ).

We then switch on the sign. If the sign is a '+' and a value is given, we simply assign the provided value to $targ. If no value is given, we assume it is a boolean flag and set $targ to be true. This is being done by an actual property associated with $targ, not by assigning some non-zero value. This is done, I assume, so we can easily distinguish those annoying "0 but true" cases.

Similarly, if the sign is '-' we check the 'true' property. If that is set, we assume this is a boolean flag and set it false. Otherwise, we simply undef the value.

Pretty straight forward, I think. But I really like the way perl6 is shaping up.

Thanks for the write up Ovid.

Mik
mikfire


Comment on Re: Poor Man's Perl6 Exegesis (you get what you pay for)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-04-16 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (417 votes), past polls