Can I not use the -E switch in the perl debugger/interpreter?

Discussion in 'Perl Misc' started by jl_post@hotmail.com, Jul 30, 2009.

  1. Guest

    Hi,

    I often create perl one-liners with the "-we" switch. I also quite
    often pop into the perl debugger/interpreter (with "perl -wde 1") to
    either test code or to run short pieces of code.

    Now that I'm using Perl 5.10, I will often replace the "-we" switch
    with "-wE" to take advantage of 5.10's "say" feature. For example,
    with this one-liner:

    perl -wE "say foreach 1 .. 3"

    we see the following output:

    1
    2
    3

    which is just what we'd expect. Thanks to the "-E" switch I can take
    advantage of the "say" feature, which allows me to omit typing the
    "\n" that print() would require me to do.

    (I know that I can use the "-l" (ell) switch to force print() to
    print a newline, but it also has other side-effects (such as stripping
    off newlines with the <> operator) that the "say" feature doesn't
    have.)

    However, if I invoke the perl interpreter/debugger, like this:

    perl -wdE 1

    and then type:

    say foreach 1 .. 3

    then I don't seem to get any output. I find this strange because I
    would think the "-E" switch would enable the "say" feature for me,
    just like it did in the above one-liner.

    (Now, I CAN use the "say" feature with this line:

    use feature 'say'; say foreach 1 .. 3

    but the "say" feature only applies in the scope of that one line,
    meaning that if I want to use "say" again, I have to re-include it as
    a feature.

    Of course, I can always rewrite that line as:

    local $\ = "\n"; print foreach 1 .. 3

    but like before, I have to retype 'local $\ = "\n";' every time I want
    that feature.)

    So my question is: Is it possible for me to use the "-E" switch in
    the perl debugger/interpreter to automatically invoke the "say"
    feature, or can that only be used with perl one-liners (that is,
    scripts written entirely at the command line)?

    (For the record, I'm seeing this behavior on both Linux and
    Strawberry Perl for Windows.)

    Thanks,

    -- Jean-Luc
     
    , Jul 30, 2009
    #1
    1. Advertising

  2. Peter Scott Guest

    On Thu, 30 Jul 2009 08:29:02 -0700, wrote:
    > So my question is: Is it possible for me to use the "-E" switch in
    > the perl debugger/interpreter to automatically invoke the "say" feature,
    > or can that only be used with perl one-liners (that is, scripts written
    > entirely at the command line)?


    The reason lies in toke.c: the debugger is loaded before -E is processed:

    if (PL_perldb) {
    /* Generate a string of Perl code to load the debugger.
    [...]
    if (PL_minus_E)
    sv_catpvs(PL_linestr,
    "use feature ':5." STRINGIFY(PERL_VERSION) "';");

    So at the moment, the answer is no. I'll ask P5P whether it has to stay
    this way.

    --
    Peter Scott
    http://www.perlmedic.com/
    http://www.perldebugged.com/
    http://www.informit.com/store/product.aspx?isbn=0137001274
     
    Peter Scott, Jul 31, 2009
    #2
    1. Advertising

  3. Guest

    > On Thu, 30 Jul 2009 08:29:02 -0700, wrote:
    > >
    > >    So my question is:  Is it possible for me to use the "-E" switch in
    > > the perl debugger/interpreter to automatically invoke the "say" feature,
    > > or can that only be used with perl one-liners (that is, scripts written
    > > entirely at the command line)?


    On Jul 31, 8:02 am, Peter Scott <> replied:
    >
    > So at the moment, the answer is no.  I'll ask P5P whether it has to stay
    > this way.


    Thanks for letting me know, Peter. I appreciate it.

    -- Jean-Luc
     
    , Jul 31, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christian Seberino
    Replies:
    14
    Views:
    762
    Tim Golden
    Dec 11, 2003
  2. Martin DeMello

    RCR: New interpreter switch

    Martin DeMello, Sep 21, 2003, in forum: Ruby
    Replies:
    3
    Views:
    120
    Martin DeMello
    Sep 21, 2003
  3. Ting Wang
    Replies:
    5
    Views:
    185
    John Bokma
    Oct 6, 2005
  4. Robert Oschler
    Replies:
    1
    Views:
    231
    Mcginkel
    Sep 5, 2005
  5. Switch Within A Switch

    , Apr 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    115
    Lasse Reichstein Nielsen
    Apr 22, 2006
Loading...

Share This Page