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


J

jl_post

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
 
Ad

Advertisements

P

Peter Scott

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.
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top