Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Perl Parsing Based on Supplied Precedence

by wirito (Acolyte)
on Nov 07, 2012 at 09:06 UTC ( #1002646=note: print w/replies, xml ) Need Help??

in reply to Re^2: Perl Parsing Based on Supplied Precedence
in thread Perl Parsing Based on Supplied Precedence

With boolean operators there is the same issue. '&&' and 'and' operator has higher precedence that '||' and 'or' (check perlop link on my first post). My approach gives accurate results.
Then 'COND1&&COND2||COND3' is the same as '(COND1&&COND2)||COND3':
$ perl COND1&&COND2||COND3 ORIG: { '&&' => [ 'COND1', { '||' => [ 'COND2', 'COND3' ] } ] } NEW: { '||' => [ { '&&' => [ 'COND1', 'COND2' ] }, 'COND3' ] }

Replies are listed 'Best First'.
Re^4: Perl Parsing Based on Supplied Precedence
by protist (Monk) on Nov 07, 2012 at 11:49 UTC

    "&&" and "and" have differing precedences. "and" is lower precedence than "&&". The same goes for "||" and "or"; "or" has lower precedence than "||". "and" actually has lower precedence than "||", as I will demonstrate.

    code with "&&":

    perl -e 'if(0&& 0||1){print"hello\n"}'



    code with "and":

    perl -e 'if(0and 0||1){print"hello\n"}'

    (outputs nothing)

      Yes, you are right. I meant to say:
      '&&' and 'and' operator has higher precedence than '||' and 'or' respectively
      English is not my first language as you can notice :)

        Ah. After I saw your precedences in your example below, I was confused because you seemed to understand haha. I will note here that I was not attempting to mirror Perl precedences in my example precedence, only create a precedence for testing purposes. Your precedence list is more Perl-like.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002646]
[shmem]: push returns the number of elements in @foo, the assignment returns all the elements in the (renewed) @foo
[Lady_Aleena]: Sanity check please? push @line, ref($list_addition ) eq 'ARRAY' ? @$list_addition : $list_addiction; # so I don't have the change existing uses of the sub.
[shmem]: $list_addiction should be $list_addition
Discipulus loose the tozzetto party!
[shmem]: .oO( addition of cookies for addiction to cookies )
[Lady_Aleena]: Other than my typos shmem. 8)
[shmem]: otherwise fine
[Discipulus]: tozzetti & vinsanto
[Lady_Aleena]: The whole line is push @line, ref($list_addition ) ? @$list_addition : $list_addition if $list_addition;
[Lady_Aleena]: And I forgot to do the array check, I'm such a doofus today.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-04-27 11:44 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (503 votes). Check out past polls.