3

I know about perlop. What I am looking for is a quick lookup like the GHCi :info command:

ghci> :info (+)
class (Eq a, Show a) => Num a where
    (+) :: a -> a -> a
    ...
    -- Defined in GHC.Num
infixl 6 +

where I learn (+) is left-associative and has a precedence level of 6 from the infixl 6 + line.

JB.
  • 40,344
  • 12
  • 79
  • 106
matthias krull
  • 4,389
  • 3
  • 34
  • 54

2 Answers2

6

I realize that it is not exactly what you ask for, but what about:

perl -MO=Deparse,-p -e "print $a+$b*$c**$d;"

it prints parentheses around the expressions according to precedence:

print(($a + ($b * ($c ** $d))));

And for things out of perl distibution, you can look on perlopquick - the pod arranged very similar manner as you specified in your question.

bvr
  • 9,687
  • 22
  • 28
  • That is interesting. Could you please explain what the comma does? – matthias krull Feb 12 '11 at 02:12
  • @mugen kenichi: `-M` loads the module (`O` in this case) and gives parameters following `=` to its import sub. It is basically equivalent to `use O qw(Deparse -p);` in your code. `O` loads specific compiler backend, in this case `B::Deparse`, `-p` being its parameter. See `perldoc B::Deparse` for full list of its options. – bvr Feb 12 '11 at 06:29
  • ah so -p is a parameter to Deparse not to perl. perlopquick is also a nice find for me. – matthias krull Feb 12 '11 at 10:49
1

Any reasonable reference manual and electronic version or help facility for the language should include the operator precedence in a list either horizontal or vertical, starting with the first entry as the highest prcedence.

developer
  • 55
  • 3