bichonfrise74 has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking at the module B::Deparse and the usage looks like this.
perl -MO=Deparse <perl program>
The "O=Deparse" throws me off, shouldn't it be "B::Deparse"? Well, I tried to use
perl -MB::Deparse <perl program>
but obviously it didn't work.

Does anyone know what the O=Deparse means or why it is not using "B::Deparse"?

Replies are listed 'Best First'.
Re: B::Deparse vs. O=Deparse
by ikegami (Patriarch) on Oct 31, 2009 at 02:00 UTC

    shouldn't it be "B::Deparse"?"

    perl -MB::Deparse -e"foo()"
    is the same as
    perl -e"use B::Deparse; foo()"

    You can use Deparse to see that:

    >perl -MO=Deparse -MB::Deparse -e"foo()" use B::Deparse; foo(); -e syntax OK

    B::Deparse loads functions to deparse Perl code. But since you never use the module, it's rather useless to load the module.

    O, on the other hand, behaves very specially when loaded. It loads the program, dumps it using the specified dumper (e.g B::Deparse), and prevents it from executing as if -c had been specified.

    >perl -MO=Deparse -e"foo()" foo(); -e syntax OK >perl -MO=Concise -e"foo()" 6 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 1 -e:1) v:{ ->3 5 <1> entersub[t2] vKS/TARG,1 ->6 - <1> ex-list K ->5 3 <0> pushmark s ->4 - <1> ex-rv2cv sK ->- 4 <#> gv[*foo] s/EARLYCV ->5 -e syntax OK >perl -MO=Terse -e"foo()" LISTOP (0x19298c0) leave [1] OP (0x19298a4) enter COP (0x19298e4) nextstate UNOP (0x1929920) entersub [2] UNOP (0x192995c) null [142] OP (0x1929940) pushmark UNOP (0x1929980) null [17] PADOP (0x19299a0) gv GV (0x182a00c) *foo -e syntax OK
Re: B::Deparse vs. O=Deparse
by Burak (Chaplain) on Oct 30, 2009 at 23:26 UTC
    it means:
    use O 'Deparse';
    and it is using B::Deparse. "O" is the front-end or the "loader" of various B:: modules (compiler backends).
Re: B::Deparse vs. O=Deparse
by AnomalousMonk (Archbishop) on Oct 30, 2009 at 23:27 UTC
    Take a look at  perldoc O and  perldoc B
Re: B::Deparse vs. O=Deparse
by bichonfrise74 (Vicar) on Oct 31, 2009 at 03:13 UTC
    Thanks ikegami for the excellent explanation.