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

Re^2: Operator Precedence Parser

by bart (Canon)
on Jun 11, 2006 at 16:28 UTC ( #554691=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
    my %function = (
      sumsq => sub  { my $sum = 0; foreach(@_) { $sum += $_*$_; } return $
    +sum; },  # sum of squares
      sqrt => sub { return sqrt shift; },
  2. or download this
        if(/\G((?i:[a-z]\w*))\s*\(/gc) {  # function '('
            my $function = $1;
            trace(sprintf "function '$function' called with %d argument%s"
    +, scalar @arg, @arg==1 ? "" : "s");
            return $function{$function}->(@arg);
  3. or download this
    Line 29 "·sumsq(3,2+2)*sqrt(36)"
    Line 29 "sumsq(·3,2+2)*sqrt(36)"
    Line 45 "sumsq(3,2+2)*sqrt(36)·" result = 150
    Stack: This value is never affected

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://554691]
[shmem]: stevieb: thanks! new thing learned, done for today ;-)
[stevieb]: hahaha! Some days I wish I could quit after learning one new thing. Often that happens before I'm one my first coffee ;)
[MidLifeXis]: OHHHH. Mea culpa - I read that as coderef (facepalm)
[stevieb]: mlx: That's easy to have done in that context. For those who don't know, it converts itself into the current sub name, much like __PACKAGE__ translates into the current package name (or class)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2017-05-24 17:32 GMT
Find Nodes?
    Voting Booth?